Home » Magento, Magento 224 March 2016

Magento 2: How to call any template block from phtml file?

In Magento 1.x, you could call/print any module’s template block in any other template (phtml) file with the following code:

In Magento 2.x, it’s slightly different.

Below is the code to call/print a custom template block in another template file in Magento 2.

Suppose, you want to call a template block (helloworld.phtml) of module Chapagain_HelloWorld, then you should write the following code:

If you would like to call template block in CMS static Block or CMS Page in Magento 2, then you can simply write the following code:

Let’s take the same example as above (calling helloworld.phtml of module Chapagain_HelloWorld).

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

    Hi, How can i pass attributes in block when using in phtml file.
    For example in cms i am using
    {{ block class=”SmBasicProductsBlockBasicProducts” name=”basicproducts” template=”Sm_BasicProducts::slider-index3.phtml” title=”Multi Vitamins” product_order_by=”best_sales” product_category=”3″ product_limitation=”6″ nb_column1=”4″ nb_column2=”3″ nb_column3=”3″ nb_column4=”2″ nb_column5=”1″ }}
    How can i write this in phtml file.