Here we will learn how to add or call phtml file on any cms page.
we can use block code to do this.
login to magento admin. Open any cms page and write block code in content section.
{{block class="Magento\Framework\View\Element\Template" template="Webkul_Test::test.phtml"}}
After using the block code phtml file will be called on cms page.
If you want to call phtml file on all cms pages then you can create a layout file to achieve this.
create layout “cms_page_view.xml” file in your module.
Put the following code in layout file.
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block class="Magento\Framework\View\Element\Template" name="test" template="Webkul_Test::test.phtml"></block> </referenceContainer> </body> </page>
Now by writing this code in layout file phtml file will be called on every cms page.