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


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


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!

1 Answer 1


You're asking how to run PHP inside a client-side rendered file which is not feasible. I believe you would need to build this yourself from scratch.

The template is set in vendor/magento/module-checkout/view/frontend/layout/default.xml

<item name="template" xsi:type="string">Magento_Checkout/minicart/content</item>

As you can see there is no file suffix, but even if there was changing this would not help you as UI Component templates are rendered client side so you will not be able to run PHP.

More importantly, why do you need to run PHP in here? It would be much easier to achieve what you need with JS.

  • We are trying to have a php call to get the active customers email to which we append to the URL of the link within the content.html, something to where the ending URL would be created as example.com/checkout/<?php $email; ?> .. Have not thought about trying to append this with JS, think that would be a valid option? Possibly have it time out for 1 second after page loads and append it via JS in an active phtml file?
    – ne0nlight
    Oct 19, 2020 at 16:09
  • Within the JS you could check if the user is logged in and if so send an Ajax request to a PHP controller which gives you their email address, then update a Knockout observable which will render to the template only when the value gets populated. magento.stackexchange.com/questions/263905/… has two solutions that may help.
    – Ben Crook
    Oct 19, 2020 at 16:23
  • Or if you Google 'Magento 2 get customer email address javascript' there are some helpful answers, just be careful not to rely on answers that are in the checkout as the customerData seems to work differently there.
    – Ben Crook
    Oct 19, 2020 at 16:24
  • Thanks for this Ben! I tried something simple like; document.getElementById("top-cart-btn-checkout").href="test.html"; however it doesn't appear to actually update the given Id, could it be due to being inside an element that has functions going on within it? The link being; <a href="link-to-change.html" id="top-cart-btn-checkout" class="action primary checkout" data-bind="attr: {title: $t('Checkout')}" title="Checkout">Link</a>
    – ne0nlight
    Oct 19, 2020 at 16:38
  • Ended up just using jquery to swap out the URLs and it works fine, thanks for the good explanation and suggestion!
    – ne0nlight
    Oct 19, 2020 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.