0

I want to add a phtml but this phtml should only visible in all cms page only ? how can I implement this using layout XML method ?

0

You can use a layout file named cms_page_view.xml. For example:

<?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 name="your_template" template="Your_Module::your-template.phtml"/>
        </referenceContainer>
    </body>
</page>
0
  1. create cms_page_view.xml in your custom extension on following location with this code.

Vendor\Extension\view\frontend\layout\cms_page_view.xml

<?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="your_block_file_path" name="my_custom_block_cms" template="Vendor_Extension::cmstemplate.phtml"/>
        </referenceContainer>
    </body>
</page>
  1. now create cmstemplate.phtml on following location.

Vendor\Extension\view\frontend\templates\cmstemplate.phtml

added code according to your requirement.

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.