Skip to content

DerFuchs/magento2-morelayouthandles

Repository files navigation


Magento 2 - More Layout Handles

Get some more useful layout handles for Magento 2
Explore the docs »

Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Installation
  3. Usage
  4. Available Layout Handles
  5. Roadmap
  6. Contributing
  7. License
  8. Contact

About The Project

This Module dynamically adds some more layout handles to specific Magento 2 pages.

This becomes very useful when you want to make changes to the layout, for example remove some blocks or move them to another location, but you want them to be available only on specific pages or for specific products, attribute sets and stuff like that. See Available Layout Handles for what's possible at the moment with this version of the module.

Built For

  • Magento 2, tested on Version 2.4.x

Installation

This module is available as a composer module for Magento 2

  1. Install to your Magento 2 by using composer
    composer require derfuchs/magento2-morelayouthandles
  2. Upgrade Magento 2
    bin/magento setup:upgrade
  3. Re-compile Magento's dependency injections
    bin/magento setup:di:compile

Usage

Enable every desired layout handle in this modules config section in Magento's admin panel. Then set your layout updates in a layout xml file:

  1. Enable the layout handle you want to use: Magento Admin -> Stores -> Configuration -> General -> More Layout Handles
  2. Check if the new layout handle appears by using a developer toolbar or enabling the debug output of this module: Magento Admin -> Stores -> Configuration -> General -> More Layout Handles -> General Settings -> Debug
  3. Create a new file named by the resulting layout handle <magento_root>/app/design/frontend/<vendor_name>/<theme_name>/Magento_Theme/layout/<layout_handle_name>.xml (You don't have to use the Magento_Theme folder, it's just an example)
  4. Start writing your layout update XML. Feel free to use this template as a starting point:
<?xml version="1.0"?>
<!--
/**
 * Some useful hints about what this layout update file does
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <!-- reference a container or a block or whatever. See Magento's layout instruction documentation for more information: https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/layouts/xml-instructions.html -->
        <referenceContainer name="container.name.you.want.to.reference">
            <!-- do stuff -->
        </referenceContainer>
    </body>
</page>
  1. Clean Caches: bin/magento cache:clean

That's it. When the layout handle occurs, Magento will bake in your layout updates.

Available Layout Handles

This is a list of all possible layout handles

Product's attribute set ID

  • available at: product detail pages
  • layout handle's name: catalog_product_view_attribute_set_id_(attribute-set-id)

Product's attribute set name

  • available at: product detail pages
  • layout handle's name: catalog_product_view_attribute_set_name_(attribute-set-name)

Didn't find what you need?

Feel free to ask for implementation or do it by yourself (and make a pull request to let others participate :) ).

Roadmap

See the open issues for a list of proposed features (and known issues).

Upcoming Version 1.1

Add layout handles on the occurance of specific product attributes

Recent Version 1.0

Layout handles for product's attribute set ID and attribute set name on product pages

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Michael Fuchs - derfuchs - michael@derfuchs.net

Project Link: https://github.com/DerFuchs/magento2-morelayouthandles

Contributors Forks Stargazers Issues MIT License LinkedIn

About

Get some more useful layout handles for Magento 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages