derfuchs / magento2-morelayouthandles
Add some more useful layout handles to Magento 2
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- magento/framework: ~100.0.0
README
Magento 2 - More Layout Handles
Get some more useful layout handles for Magento 2
Explore the docs »
Report Bug
·
Request Feature
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
- 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
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:
- 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.
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.
- 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
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