6

I am new to Magento and so sorry for the noddy question.

I am trying to add php to a CMS page and the way to do this appears to be to put the php (including Mage calls) to a phtml template and then add it to the CMS page with {{block type="core/template" template="template.phtml"}}.

But, in all the examples that I can find saying that this is the way to do it none of them tell me where to put the phtml file so I can use the above.

So my question is; where do I put a template to call using {{block type="core/template" template="template.phtml"}}?

Thanks in advance, Norman

7

The template file is relative to your theme's template folder. But also taking into consideration the template fallback (see this for more details) you have 2 options:

  1. add the template file in your current theme:

    app/design/frontend/[YOUR_PACKAGE]/[YOUR_THEME]/template/[CUSTOM_FOLDER]/[TEMPLATE].phtml
    
  2. add the template file in the base package:

    app/design/frontend/base/default/template/[CUSTOM_FOLDER]/[TEMPLATE].phtml
    

Then, in your CMS page you will add {{block type="core/template" template="[CUSTOM_FOLDER]/[TEMPLATE].phtml"}}

Where [YOUR_PACKAGE] and [YOUR_THEME] are the currently used package and theme folders used on your store, and [CUSTOM_FOLDER] and [TEMPLATE] can be anything on your choice

  • alex.ayg and @Joshua43com - Thank you both for your replays. While working through what you have advised (even though I was sure I had tried this) I have realised that the reason that it was not working was that I had not clicked 'Hide Editor' before I had typed it. What you have advised has worked so thank you. Sorry for being such a fool. :) – Norman_SK Sep 14 '14 at 1:11
2

Welcome to Magento SE.

An easy way to make this call from a static block is, add this to your static block:

{{block type="core/template" template="page/template.phtml"}}

Place page.phtml at this path, with your custom code:

app/design/frontend/package_name/theme_name/template/page/template.phtml

If you are still having problems, due to Magento's hierarchy, you can also place it here:

app/design/frontend/base/default/template/page/template.phtml

Be sure to flush your cache

0

I try to do the same:

I created a file mycms.phtml in this folder:

app/design/frontend/base/default/template/cms

On the static page content/pages/mycmspage I added this line

{{block type="core/template" template="cms/mycms.phtml"}}

the testfile mycms.phtml only contains

<?php echo "test php"; ?>

This is not working for me?

also when placing the file here:

app/design/frontend/[myvendor]/[mytheme]/template/cms

My theme is a child theme of luma

is not working?

please advice

  • I use magento 2.3.1 – goodlook Jun 1 '19 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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