0

Inside the magento/module-cms/frontend/layout: enter image description here

I created my selectable xml file and inside of it had this code:

enter image description here

I go to my magento admin > cms page > set the custom layout update and there is no changes also tried to clear the cache and still remains. The thing that I'm trying to do is remove the header and footer on a certain cms page.

1 Answer 1

1

You shouldn't edit code directly from magento codebase: vendor/magento.

To add a selectable layout to CMS page, create a selectable layout file for CMS pages:

cms_page_view_selectable_<CMS Page Identifier>_<Layout Update Name>.xml

where:

  • CMS Page Identifier is the desired page’s URL Key with “/” symbols replaced with “_”.
  • Layout Update Name is what is shown as the option for the Custom layout update field of the Design section on the CMS Page Edit page. For example, a layout update for an “About Us” page will be “cms_page_view_selectable_about-us_AboutUs.xml”.

This file must be placed in the appropriate folders for layout XML files, it be located in:

  • in your module: <module dir>/view/frontend/layout
  • in your theme: <theme dir>/Magento_Cms/layout

Sample code for cms_page_view_selectable_about-us_AboutUs.xml file (your file content should be the same):

<?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="header.container" remove="true"/>
        <referenceBlock name="catalog.topnav" remove="true"/>
        <referenceContainer name="footer-container" remove="true"/>
    </body>
</page>

Flush the cache and go to CMS Page Edit page, the new selectable layout was added in Custom Layout Update field of the Design section.

Source: https://magetu.com/how-to-add-a-selectable-layout-to-cms-page-in-magento-2

3
  • Hi, I appreciate ur answer. Please check my updated post about this issue. Thanks. Commented Oct 6, 2022 at 13:50
  • @LichaelHipolito looks like your selectable layout file name is incorrect. There are 3 parts in this file: part 1: cms_page_view_selectable_, part 2 is the CMS Page Identifier - which is the URL Key (replace "/" with "_" if URL Key has "/" character), part 3 is Layout Update Name - you can set the name as you want but not using space or special characters. Another example, the selectable layout file name for privacy-policy-cookie-restriction-mode page is: cms_page_view_selectable_privacy-policy-cookie-restriction-mode_PrivacyPolicy.xml
    – Tu Van
    Commented Oct 6, 2022 at 14:12
  • @LichaelHipolito please don't edit magento codebase (vendor/magento) because after you upgrade magento version, your changes will be lost.
    – Tu Van
    Commented Oct 6, 2022 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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