Fill the form & Get Installation Support

    We will create a new category page layout and use that layout using the custom category attributes in Magento 2.

    Why would you need to add a custom layout to a category?
    1. To add your custom css for specific page.
    2. Insert more page information.
    3. To add custom JS to the page, such as GTM script.

    We will use events and observers to add a custom layout to the category page. We will use the layout_load_before because there is no other point to append a custom layout until the page is rendered.

    Please follow the below steps.

    Step 1: Create a custom module then add below files in that created module. For example assume that i have created “Magemonkeys/CategoryLayout”.

    Step 2: Create InstallData.php at app/code/Magemonkeys/CategoryLayout/Setup/
    Here we create the custom category attribute code as shown below:

    Step 3: Create category_form.xml at app/code/Magemonkeys/CategoryLayout/view/adminhtml/ui_component/

    Here we display the Custom Category attribute on the Display Settings tab in the Admin Side Category View page:

    Now you can check this layout in the admin panel configuration.

    Step 4: Create events.xml at app/code/Magemonkeys/CategoryLayout/etc/frontend/

    Here we use the layout_load_before code.

    Step 5: Create Categorycustomlayout.php at app/code/Magemonkeys/CategoryLayout/Observer/
    Here we check the category attribute is enabled/disabled and add the layout handle for page layout.

    Step 6: Create catalog_category_custom_view.xml at app/code/Magemonkeys/CategoryLayout/view/frontend/layout/

    Here we remove the sidebar wishlist and custom class.

    Apply some CSS for styling and you’ll have your new page layout with new customised content a couple of times.

    Fill the below form if you have any Magento programming need.

      Recent Articles

      Author Info

      Hire B. Darji

      Get a Free Quote

        Let our Magento expert connect to discuss your requirement.

          We offer Magento
          certified developers.

          Our Magento clientele
          is 500+.

          We sign NDA for the
          security of your projects.

          We’ve performed 100+
          Magento migration projects.

          Free quotation
          on your project.

          Three months warranty on
          code developed by us.