1

I want to make a cms static block which should display/render the content of a .phtml file (echo "Test1"). Content of my cms static block:

<div id="something">
     {{block class="Magento\Catalog\Block\Product\View\Description" name="test" template="product/view/test1.phtml" }}
</div>

something like that. Would this work out ?

Location of "test1.phtml" is in vendor\magento\module-catalog\view\frontend\templates\product\view\test1.phtml

Also: what if I change location of "test1.phtml", how can I write it in {{ ... }} ?

2 Answers 2

6

You can use Magento\Framework\View\Element\Template basic template.

Try this:

<div id="something">
    {{block class="Magento\Framework\View\Element\Template" name="test" template="path/to/my/file.phtml" }}
</div>

This should work.

UPDATE:

If you need to display product information you have to use blocks from prduct view. Example:

<div id="something">
    {{block class="Magento\Catalog\Block\Product\View\Description" name="test" template="path/to/my/file.phtml" }}
</div>

PHTML file position depends on your architecture. If you are not embedding this in a module you could put it in your template.

Example:

<div id="something">
    {{block class="Magento\Catalog\Block\Product\View\Description" name="test" template="Magento_Theme::mytemplate.phtml" }}
</div>

And put your file under: design/frontend/yourtheme/default/Magento_Theme/mytemplate.phtml

2
  • Thanks again ! I'm using class="Magento\Catalog\Block\Product\View\Description" because I need to display product-sku attribute. One question: template="var/test1.phtml" would also work, if that would be it's location ? Commented Dec 24, 2016 at 17:13
  • See my updated post Commented Dec 24, 2016 at 17:23
1

Use class "Magento\Framework\View\Element\Template" and you can also pass any value if required:

{{block class="Magento\Framework\View\Element\Template" name="test_file" testId="66" template="Magento_Catalog::product/widget/test.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.