Reading list Switch to dark mode

    Call Phtml file on CMS Page – Magento2

    Updated 23 February 2024

    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="Webkul_Test::test.phtml"}}
    call phtml

    After using the block code phtml file will be called on cms page.

    call phtml

    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.

    Searching for an experienced
    Magento 2 Company ?
    Find out More
    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    3 comments

  • Robert Jung
    • WorldClick
      • John C
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home