2

I'm trying to call a phtml file in a CMS Page and I know that there are several question for exactly that question already on Stackexchange. The problem is: its not working. I can't get it to running so obviously I'm doing something wrong right now.

This is my theme structure: app/design/fronend/MX/base/

The desired phtml file is here: app/design/fronend/MX/base/MX_Slider/template/carousel.phtml

In my CMS Page I use the following: {{block class="Magento\Framework\View\Element\Template" name="MX" template="MX_base::MX_Slider/template/carousel.phtml"}}

However, the phtml is not showing on the page.

Any ideas why? What am I missing?

0

2 Answers 2

9

Try this

custom file path(Based on your theme you can change it)

app/design/frontend/{Package}/{theme}/Magento_Theme/templates/html/test.phtml

calling in xml layout file

<block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"/>

calling in blocks and cms pages

{{block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"}}

calling in any phtml file

<?php include ($block->getTemplateFile('Magento_Theme::html/test.phtml')) ?>

OR
as before

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/test.phtml")->toHtml();?>
8
  • Nothing changes - theres no output. Right now I only have Lorem Ipsum content in carousel.phtml, do I need to put anything special in there? Also, I already have read the link you've posted. I tried the code from there but I have a problem setting the path in template correctly... Somehow the shortcut doesn't work!
    – Max
    Commented Mar 30, 2016 at 18:43
  • File is calling or not
    – Magento 2
    Commented Mar 30, 2016 at 18:44
  • No, there is no output on the page. Is there another way to check if "the file is calling or not" - im not sure how this is meant.
    – Max
    Commented Mar 30, 2016 at 18:45
  • Your Theme name
    – Magento 2
    Commented Mar 30, 2016 at 18:47
  • In the theme.xml it's defined as "MX CC". Not really sure if this is what you want to know
    – Max
    Commented Mar 30, 2016 at 18:49
0

use following code in your cms page:-

{{block class="Magento\Framework\View\Element\Template" name="MX" template="MX_Slider::carousel.phtml"}}

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.