How to Call Phtml file on CMS Page – Magento2
In this post we will show you How to Call Phtml file on CMS Page, hear for How to Call Phtml file on CMS Page we will give you demo and example for implement.
Here we will learn
how to add or call phtml file on any cms page. we can use block code to do this.
Call Phtml Using Block Code
login to magento admin. Open any cms page and write block code in content section.
{{block class="Magento\Framework\View\Element\Template" template="We_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="We_Test::test.phtml"></block> </referenceContainer> </body> </page>
Now by writing this code in layout file phtml file will be called on every cms page.
Hope this code and post will helped you for implement How to Call Phtml file on CMS Page – Magento2. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org