In Magento 1, themes had a special file named local.xml
. Through this file, a Magento 1 theme could directly modify the layout without needing to replace a specific layout update XML file.
Does Magento 2 have a similar mechanism? I know a Magento 2 theme can replace a layout handle XML file from a module — what I want to know is does Magento 2 have a way for a theme to add layout rules that are specific to that theme.
If not, are there classes/methods provided that would allow a module developer to only add certain layout rules when a certain theme is added?
Best Answer
You have two options, you can either extend or overwrite the existing XML.
Extending
To extend an existing layout in a similar fashion to local.xml in Magento 1 you need to add an XML file in a location like this:
Where
<layout1>
and<layout2>
are your layout handles, for example:Official documentation can be found here - http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-extend.html
Overwriting
Overwriting XML is done in the same way, it's just the file location that changes. You can overwrite the base module's XML or the parent theme's XML, the file location determines which is overwritten.
To overwrite the base module's XML place your XML file in:
To overwrite the parent theme's XML place your XML file in:
Official documentation can be seen here - http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-override.html