Monday, November 16, 2015

How to call a PHTML file within a CMS page Magento 2 ?

To call a phtml file in a cms page or cms static block:

{{block class="Magento\Framework\View\Element\Template" template="PackageName_ModuleName::your_template.phtml"}}
 
If you know, where the block file(php file) for your phtml file resides, then you can use it as type.
Example: Suppose you want to call new.phtml file that resides in catalog/product folder, and you know that its corresponding Block file(php file) resides in Catalog/Product folder, then you can use:

{{block class="Magento\Framework\View\Element\Template" template="PackageName_ModuleName::catalog/new.phtml"}}
 
 
 

4 comments:

  1. Replies
    1. for "Call Phtml file on CMS Page" Magento 2 check this
      http://www.onlinecode.org/call-phtml-file-cms-page-magento2/

      Delete
  2. Update your title or update your answer!

    ReplyDelete
  3. Thank you Raji. I have updated my answer. It was posted before Magento 2 stable version launched.

    ReplyDelete