:::: MENU ::::

Magento 2 call a phtml file in static block

Magento 2 call a phtml file in static block

Today we talk about how to in Magento 2 call a phtml file in static block. Calling a phtml file is no different as compared to Magento 1 calling. But if you are calling it in cms block you have to use a class instead of type.

Calling a phtml file on the static block. Just add class and template path.

My current file location for the module is.

app/code/QaisarSatti/HelloWorld/Block/HelloWorld/view/frontend/templates/helloworld.phtml

{{block class="QaisarSatti\HelloWorld\Block\HelloWorld" template="QaisarSatti_HelloWorld::helloworld.phtml"}}

My current phtml location for the theme is.

app/design/frontend/QaisarSatti/helloworld/Magneto_Theme/templates/helloworld.phtml

{{block class="QaisarSatti\HelloWorld\Block\HelloWorld" template="helloworld.phtml"}}

If you want to add phtml with general magento class. Use following code.

{{block class="Magento\Framework\View\Element\Template" template="helloworld.phtml"}}

Give A Rating

Average Rating / 5. Vote Count

Author: Qaisar Satti
Category: Magento 2
Last Modified: November 28, 2019


So, what do you think ?