TransWikia.com

Magento 2: Add custom category layout to multiple categories

Magento Asked by MaddocksL on February 9, 2021

I am trying to add a custom category layout to my theme. I have the standard catalog_category_view.xml and have got the update for 1 category using catalog_category_view_id_[id].xml.

I want to apply the update to multiple categories (around 30) without having to create multiple catalog_category_view_id_[id].xml for each category. Any further updates would have to be made across every file.

Is there a way to have a layout update in the design section?
enter image description here

One Answer

Override vendor layouts.xml into your theme:

vendormagentomodule-themeviewfrontendlayouts.xml

into

app/design/frontend/[Vendor_Name]/[Theme]/Magento_Theme/layouts.xml

Add the below code into layouts.xml for the custom category layout.

<layout id="custom-category-layout">
    <label translate="true">Custom category layout</label>
</layout>

Create custom-category-layout.xml file in your theme by copy code 2columns-left.xml:

app/design/frontend/[Vendor_Name]/[Theme]/Magento_Theme/page_layout/custom-category-layout.xml

Finally, create catalog_category_view.xml in your theme: app/design/frontend/[Vendor_Name]/[Theme]/Magento_Catalog/layout/catalog_category_view.xml

Update the layout name just like below:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="custom-category-layout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

Now select a custom theme and category layout from admin for multiple categories.

enter image description here

Note: Due to custom layout, body class page-layout-2columns-left will be updated with a new one and the sidebar will not display. For that, you can add CSS by checking the two-column page layout and it will work.

Hope it will help!

Answered by Vikram Kumar on February 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP