0

I want to create a custom layout for one or more categories. I followed the next steps:

  • Extended and customized <theme_dir>\Magento_Catalog\layout\catalog_category_view.xml (layout instructions work fine)
  • Created the custom layout <theme_dir>\Magento_Theme\page_layout\custom-category-layout.xml

custom-category-layout.xml

<?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="1column"/>
    <body>
        <referenceBlock name="footer" remove="true" />
    </body>
</layout>
  • Then added the layout in <theme_dir>\Magento_Theme\layouts.xml

layouts.xml

<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
    <layout id="custom-category-layout">
        <label>Category custom layout</label>
    </layout>    
</page_layouts>

  • Cleared the cache.
  • Selected the Category custom layout in the category.
  • Cleared the cache.
  • But layout instructions are not reflected on the browser.

What am I missing?

1
  • please run php bin/magento indexer:reindex and check. may it can help Dec 1, 2021 at 4:16

3 Answers 3

0

This link will help you for this . https://www.rakeshjesadiya.com/add-category-custom-layout-update-xml-file-magento-2-3-4/

0

I have finally managed to solve the problem. Next I will explain how I have generated custom layouts for specific categories.

I created a layout in <theme_dir>\Magento_Catalog\layout\catalog_category_view_selectable_<CATEGORY_ID>_<CATEGORY_NAME>. For example: catalog_category_view_selectable_2_accesories.xml

Then I created another layout in <theme_dir>\Magento_Theme\page_layout\custom-category-<CATEGORY_NAME>.xml. Example: custom-category-accesories.xml

In my case, I have separated store views and the Custom Layout Update select only shows the custom layout update if I go to a certain store view.

Hope my solution helps more than one.

1
  • there is no need to create Then I created another layout in <theme_dir>\Magento_Theme\page_layout\custom-category-<CATEGORY_NAME>.xml. Example: custom-category-accesories.xml. Check my answer for more information.
    – Sumit
    Oct 19, 2022 at 11:34
0

It totally depends on the theme configuration. If you've added the layout in your custom theme and the custom theme is assigned to the store view then you can only update the custom layout update by changing the scope from All store views to the specific store view.

If your custom theme is setup globally in the theme configuration, you can see the custom layout from the All store view.

For Categories:

catalog_category_view_selectable_<Category ID>_<Layout Update Name>.xml

where:

  • Category ID is desired category ID.
  • Layout Update Name is what is shown as the option for Custom layout update field of Design section on Category Edit page.

For Products:

catalog_product_view_selectable_<Product SKU>_<Layout Update Name>.xml

where:

  • Product SKU is the desired product's SKU encoded as a URI. example: "My Product SKU" -> "My%20Product%20SKU" Layout Update Name is what is shown as the option for Custom layout update field of Design section on Product Edit page

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".

Hope this will helps!!!

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.