Get some more useful layout handles for Magento 2
Explore the docs »
Report Bug
·
Request Feature
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.
- Magento 2, tested on Version 2.4.x
This module is available as a composer module for Magento 2
- Install to your Magento 2 by using composer
composer require derfuchs/magento2-morelayouthandles
- Upgrade Magento 2
bin/magento setup:upgrade
- Re-compile Magento's dependency injections
bin/magento setup:di:compile
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:
- Enable the layout handle you want to use:
Magento Admin -> Stores -> Configuration -> General -> More Layout Handles
- 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
- 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) - 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>
- Clean Caches:
bin/magento cache:clean
That's it. When the layout handle occurs, Magento will bake in your layout updates.
This is a list of all possible layout handles
- available at: product detail pages
- layout handle's name: catalog_product_view_attribute_set_id_(attribute-set-id)
- available at: product detail pages
- layout handle's name: catalog_product_view_attribute_set_name_(attribute-set-name)
Feel free to ask for implementation or do it by yourself (and make a pull request to let others participate :) ).
See the open issues for a list of proposed features (and known issues).
Add layout handles on the occurance of specific product attributes
Layout handles for product's attribute set ID and attribute set name on product pages
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Michael Fuchs - derfuchs - [email protected]
Project Link: https://github.com/DerFuchs/magento2-morelayouthandles