Say you have a phtml file and you want to include in below sections in Magento 2.
Calling PHTML in XML
Calling PHTML in Blocks/CMS Page
Calling PHTML in PHTML File
OR
<?xml version="1.0"?><page xmlns:xsi="<a class="vglnk" href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow"><span>http</span><span>://</span><span>www</span><span>.</span><span>w3</span><span>.</span><span>org</span><span>/</span><span>2001</span><span>/</span><span>XMLSchema</span><span>-</span><span>instance</span></a>" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"><body><referenceContainer name="content"><blockclass="Magento\Framework\View\Element\Template"name="test"template="Magento_Theme::myfile.phtml"></block></referenceContainer></body></page>
Calling PHTML in Blocks/CMS Page
{{block class="Magento\Framework\View\Element\Template" name="myfile_block_name" template="Magento_Theme::html/myfile.phtml"}}
Calling PHTML in PHTML File
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/myfile.phtml")->toHtml();?>
OR
<?php include ($block->getTemplateFile('Magento_Theme::html/myfile.phtml')) ?>

No comments:
Post a Comment