cancel
Showing results for 
Search instead for 
Did you mean: 

Using small PHP script in .html file (or) Changing .html file to .phtml

Highlighted

Using small PHP script in .html file (or) Changing .html file to .phtml

Hello!

We are running into an issue where we need to run a little php script within a .html file in Magento 2, namely;

/app/design/frontend/CleverSoft/core/Magento_Checkout/web/template/minicart/content.html

When we have tried adding the ability for html files to run php via the .htaccess, it ends up causing other errors within Magento so it just ends up breaking more things. Namely, using things like;

AddType application/x-httpd-php56 .php .htm .html

or

AddType application/x-httpd-php .html .htm

Are there other alternatives to try to run php within this html file, or is it possible to change this file to .phtml like so many of the others? I would just have to find where it is originally called I assume and change that from .html to .phtml?

Thanks for the insight!

3 REPLIES 3
Highlighted

Re: Using small PHP script in .html file (or) Changing .html file to .phtml

Hello @WinteRx182 

 

The html files would not allow you to run php code inside it, but .phtml does,

a .phtml file can run either php code or html code or both together.

 

It will surely work with .phtml what you are trying.

 

Hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !
Highlighted

Re: Using small PHP script in .html file (or) Changing .html file to .phtml

Hey @gaurav_harsh1 

 

I agree! That would work perfectly, however the file as is, is .html and I am not sure where it is loaded to where I can change that loading section to .phtml, thus being able to change the actual file to .phtml.

 

Is there a way to see where the actual file is loaded from?

 

Thanks!

Highlighted

Re: Using small PHP script in .html file (or) Changing .html file to .phtml

@WinteRx182 

 

Yes, Definitely there is way to find, you can use Template Path Hints it will show you the template from the content is loading, but it has limitations for the some pages for

EX : Checkout page

Follow the docs how to enable it (please ensure that your mode is developer and you add URL of ?templatehints=VALUE to see path hints)

 

NOTE : if you find that files are loading from core module, don't change in that particular file, extend it in your theme Smiley Happy

Example : https://magento.stackexchange.com/questions/116389/how-to-override-phtml-files-in-magento-2

 

Hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !