Using PHP code in HTML

4 replies · opened Jun 3, 2020

BBharatJun 3, 2020

Hi,

Yesterday only I bought your template for creating a photography site, I am using your Photography template. what I need it to add PHP code to photography.HTML file to be able to read all files in the directory and add them to the slider.
Like,
<?php
$dirname = "images/";
$images = scandir($dirname);
shuffle($images);
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<li><a href='".$dirname.$curimg."'><img src='img.php?src=".$dirname.$curimg."&w=300&zc=1' alt='' /></a></li>\n";
}
}
?>

However, no matter where I add this in the HTML, at runtime the php code gets commented.

is it not possible to process PHP within the HTML file? Please help.

BBharatJun 3, 2020

Same is the Case with js the script block doesn't get processed however, unlike PHP it doesn't get commented.

SSemicolon WebSTAFFJun 3, 2020

Hello,

PHP Codes do not work in Files with the .html extension. Simply change the File's extension to .php and then you will be able to execute the PHP Codes.

For JS, this could be an issue with your codes. You can check the errors related to this in your Browser's developer console. Else, please provide us with a Live URL so that we can check out the exact issue and provide you with more assistance on this. Thanks for your Patience.

Meanwhile, do let us know if we can help you with anything else or if you find any further issues with Canvas.

BBharatJun 9, 2020

For php thing, it was my mistake index.php and index.html both were there and by default html was picked up, removing .html helped.

JS I still have to figure out as it works partially however, no error in the console, I will let you know in case I would need help.

Thanks

SSemicolon WebSTAFFJun 9, 2020

Hello,

This issue could be related to Custom JS Codes and not with the Template Codes. Also, the Canvas does not include any JS Codes that will prevent Custom JS Codes from running. Meanwhile, if you have a Live URL, let us know, so that we can check out the exact issue and provide you with more assistance on this. Thanks for your Patience.

Meanwhile, do let us know if we can help you with anything else or if you find any further issues with Canvas.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard