0

I just started working on magento 2 and i want to call a phtml file for every cms page. I have created a theme and under Magento_Cms i have copied cms_page_view.xml from vendor and placed it in there.Now i added below code there.

<?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\Cms\Block\Page" name="cms_page"/>
            </referenceContainer>
            <referenceContainer name="maincontent">
                <block class="Magento\Cms\Block\Page" name="custom.page.title" before="-" template="Magento_Cms::page/title.phtml"/>
            </referenceContainer>
        </body>
    </page>

page/title.phtml placed inside Magento_Cms/templates/page/title.phtml and i used die there.. and after flushing cache my phtml is not getting call. I am not able to see die effect on page. Please suggest me how can i render custom phtml file for all cms pages using xml

0

You can try to create custom module and copy core cms_page_view.xml in your module's view/layout/ folder

use this code in cms_page_view.xml

<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="Aman_Custom::test.phtml"></block>
        </referenceContainer>
    </body>
</page>

I have tried with custom module its working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.