0

Have custom layout updates generally available for all pages, categories and products, so users can select and update the layout without creating many files with the same code over and over. It would save time if the user wants only to repeat an already made custom layout update. enter image description here

cms_page_view_selectable_2021-11-23_empty.xml
cms_page_view_selectable_2021-11-24_empty.xml
cms_page_view_selectable_2021-11-25_empty.xml

If I have a lot of page layouts like this. You don't have to create a lot of XML files like this. Feels too unreasonable whether there is a method that only needs to create a file. You can use a lot of pages How to do that, Who can help me? Thank you very much

1
  • In this layout, I want to remove the header footer. How do I do that
    – sq y
    Commented Nov 30, 2021 at 5:03

1 Answer 1

0

You need to create two files for custom layout

1 - Create layouts.xml

app/design/frontend/Vendor/yourtheme/Magento_Theme/layouts.xml

This file will registered custom layout

<?xml version="1.0" encoding="UTF-8"?>
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
    <layout id="custom">
        <label translate="true">custom layout</label>
    </layout>
</page_layouts>

After creating above file you can check your custom layout in admin panel.

2 - Create custom.xml

app/design/frontend/Vendor/yourtheme/Magento_Theme/page_layout/custom.xml

This file will manage design for your layout page.

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container" htmlTag="header" htmlClass="page-header" before="main.content"/>
        <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer"/>
    </referenceContainer>
</layout>

Now, flush the cache and check the new custom layout in admin panel configuration setting.

enter image description here

12
  • Maybe I didn't describe the problem clearly.
    – sq y
    Commented Nov 29, 2021 at 5:17
  • Good question. One project I checked, for better or worse, was re-using the same custom layout update across ~800 categories. In order to migrate to the new system this would require 800 physical custom layout files, one for each category, which is a laughable prospect. In addition to the ability to create custom layout update files that are specific to one product, category, or cms page, I think there also needs to be the ability to create globally available custom layout updates, that can be applied to any given entity.
    – sq y
    Commented Nov 29, 2021 at 5:23
  • my cmspage layout :cms_page_view_selectable_2021-11-22_empty.xml ;cms_page_view_selectable_2021-11-23_empty.xml ;cms_page_view_selectable_2021-11-24_empty.xml;Is there a common layout method
    – sq y
    Commented Nov 29, 2021 at 5:24
  • Reference: github.com/magento/magento2/issues/26901 There are instructions here but I can't find the answer
    – sq y
    Commented Nov 29, 2021 at 5:29
  • Please follow this link magecomp.com/blog/… Commented Nov 29, 2021 at 9:14

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.