Download the PHP package zero1/layout-xml-plus without Composer
On this page you can find all versions of the php package zero1/layout-xml-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zero1/layout-xml-plus
More information about zero1/layout-xml-plus
Files in zero1/layout-xml-plus
Package layout-xml-plus
Short Description Intercept block html output with layout xml, removing the need to override templates in most cases.
License GPL-3.0-or-later
Informations about the package layout-xml-plus
Zero1_LayoutXmlPlus
This module is aimed at reducing the need to override templates for blocks. For example, changing a single class for a button shouldn't require you to override the template. However for significant dom structure changes we would still recommend overriding the template.
Installation
composer require module enable setup:upgrade
Actions
The functionality has been split into "actions" different actions that can be taken on the output of a blocks html before it is passed to a user.
Common Parameters
action
: id of the action you wish to carry outxpath
: an xpath expressing to identify elements within the template. For compatibilty all templates are rendered inside a<root>
node, so if you wanted the first div you would want something like(/root/div)[1]
or 2nd div:(/root/div)[2]
or all divs/root//div
.
AttributeValueReplace
id: attribute_value_replace
Replace a value within an attributes value, a good example would be replacing a class with another class.
example
catalog_category_view.xml
AttributeValueSet
id: attribute_value_set
Completely override the value of an attribute
example
catalog_category_view.xml
AttributeValueAppend
id: attribute_value_append
Add an item to an attributes list of values (e.g add a class)
example
catalog_product_view.xml
example
catalog_product_view.xml
AttributeValueRemove
id: attribute_value_remove
Remove a value from an attributes list of values
example
catalog_product_view.xml
AttributeRemove
id: attribute_remove
Completely remove an attribute
example
catalog_product_view.xml
ChildHtml
id: child_html
Insert a childs html into a specific part of the output. This requires you to add the child block in layout xml.
Valid targets
start
: at the begining of the nodes content (before current children)end
: at the end of the nodes content (after current children)before
: before the current nodeafter
: after the current node
example
default.xml
Remove
id: remove
Remove an element from the dom.
example
default.xml
XPath Cheat Sheet
- select all labels with a class of 'swatch-option'
/root//label[contains(@class, 'swatch-option')]
Other Recommendations
When it comes to stopping blocks outputting content, using layout xml can often remove the requirement to change the template. N.B when referencing a block you must use it's name and not it's alias Example dont do
do
TODO
- [ ] make debug flag setable/env'able
- [ ] make play nice with hyva when prod mode