Magento2 Snippets

|| Call phtml file in static block or cms page

   custom file path(Based on your theme you can change it)
   app/design/frontend/{Vendor}/{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();?>


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s