PHPackages                             zero1/layout-xml-plus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. zero1/layout-xml-plus

ActiveMagento2-module[Templating &amp; Views](/categories/templating)

zero1/layout-xml-plus
=====================

Intercept block html output with layout xml, removing the need to override templates in most cases.

1.1.2(3mo ago)5210↓50%1GPL-3.0-or-laterPHP

Since May 15Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/zero1limited/magento2-module-layout-xml-plus)[ Packagist](https://packagist.org/packages/zero1/layout-xml-plus)[ RSS](/packages/zero1-layout-xml-plus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (11)Used By (0)

Zero1\_LayoutXmlPlus
====================

[](#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
------------

[](#installation)

```
composer require zero1/layout-xml-plus
php bin/magento module:enable
php bin/magento setup:upgrade

```

Actions
-------

[](#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 out
- `xpath`: an xpath expressing to identify elements within the template. For compatibilty all templates are rendered inside a `` 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

[](#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`

```

                /root//section[@id="product-list"]]]>
                attribute_value_replace
                class
                py-8
                pb-8

```

### AttributeValueSet

[](#attributevalueset)

id: `attribute_value_set`

Completely override the value of an attribute

example `catalog_category_view.xml`

```

                /root//section[@id="product-list"]]]>
                attribute_value_set
                id
                product-list-wrapper

```

### AttributeValueAppend

[](#attributevalueappend)

id: `attribute_value_append`

Add an item to an attributes list of values (e.g add a class)

example `catalog_product_view.xml`

```

                /root//section]]>
                attribute_value_append
                class
                c-pdp-container

```

example `catalog_product_view.xml`

```

                (/root/section/div/div)[1]]]>
                attribute_value_append
                class

                    flex
                    flex-wrap
                    order-first

```

### AttributeValueRemove

[](#attributevalueremove)

id: `attribute_value_remove`Remove a value from an attributes list of values

example `catalog_product_view.xml`

```

                (/root/section/div/div)[1]]]>
                attribute_value_remove
                class

                    grid
                    grid-rows-auto
                    grid-cols-1
                    md:gap-x-5

```

### AttributeRemove

[](#attributeremove)

id: `attribute_remove`

Completely remove an attribute

example `catalog_product_view.xml`

```

                (/root/section/div/div)[1]]]>
                attribute_remove
                @click

```

### ChildHtml

[](#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 node
- `after`: after the current node
- `replace`: replace the target node with the content of the block

example `default.xml`

```

                (/root/div)[1]]]>
                child_html
                footer.social_icons
                start

```

### Remove

[](#remove)

id: `remove`

Remove an element from the dom.

example `default.xml`

```

                (/root//a[contains(@class, "title-font")])]]>
                remove

```

XPath Cheat Sheet
-----------------

[](#xpath-cheat-sheet)

- select all labels with a class of 'swatch-option' `/root//label[contains(@class, 'swatch-option')]`

Other Recommendations
---------------------

[](#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

```

```

CLI Commands
------------

[](#cli-commands)

### Module Status

[](#module-status)

Disabling the module is a quick way to debug if layout-xml is responsible for a change you are seeing.

- Show module status: `php bin/magento dev:layout-xml-plus:status`
- Disable module: `php bin/magento dev:layout-xml-plus:status --disable`
- Enable module: `php bin/magento dev:layout-xml-plus:status --enable`

### Logging

[](#logging)

Enabling logging will cause the module to log out all changes to output, as well as fails to change output (i.e when the xpath doesn't match anything in the content)

- Show logging status: `php bin/magento dev:layout-xml-plus:logging`
- Disable logging: `php bin/magento dev:layout-xml-plus:logging --disable`
- Enable logging: `php bin/magento dev:layout-xml-plus:logging --enable`

When enabled logging will output all blocks that have any layout-xml-plus directives into `var/layout-xml-plus/logging/*`Each block will be stored as:

- `NAME_IN_LAYOUT.orig.html` - the original content of the block
- `NAME_IN_LAYOUT.new.html` - the content after modification

### Collection / Evaluation

[](#collection--evaluation)

The module also includes as way to find template overides that can be replaced with layout xml directives.

1. Magento setup ``bash php bin/magento deploy:mode:set developer
    &amp;&amp; php bin/magento cache:enable
    &amp;&amp; php bin/magento cache:flush

```
2. Enable collection (with theme)
```bash
php bin/magento dev:layout-xml-plus:collect --with-theme --clear

```

3. Browse the site Visit a set of pages, carry out a specific set of actions. The order doesn't really matter but it's important you remember eaxtly what you did/do.
4. Enable collection (without theme)

```
php bin/magento dev:layout-xml-plus:collect --without-theme --clear \
  && php bin/magento cache:flush
```

5. Clear out theme files

```
find ./app/design/frontend/ -type f -name '*.phtml' -exec rm "{}" \;
```

6. Try to browse the site the same as you did in step 3. If you hit errors, like "missing template file" This will be for blocks that have been added by the theme and not included in Magento core. Either remove their declaration from layout xml, or restore the template file. (`git checkout app/design/frontend/theme/path/to/file.phtml`) Each time you hit an error you will need to re-run

```
php bin/magento dev:layout-xml-plus:collect --without-theme --clear \
  && php bin/magento cache:flush
```

and browse the site again. example error: `1 exception(s): Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Magento_Cms::static-blocks/pagetop.phtml' in module: '' block's name: 'pagetop'`example fix: `git checkout app/design/frontend/VENDOR/THEME/Magento_Cms/templates/static-blocks/pagetop.phtml`7. Once you are happy that you have managed to browse the site without the theme files, disable collection

```
php bin/magento dev:layout-xml-plus:collect --disable
```

restore your theme

```
git checkout app/design/frontend
```

8. Get the anlysis

```
php bin/magento dev:layout-xml-plus:analyse
```

This will output a report `pub/layout-xml-report.html` which (depending on your web server configuration) should be viewable in your web browser.

Testing XPath Values
--------------------

[](#testing-xpath-values)

If you cannot find a suitable Browser extension to validate the best XPath selector values, you can use the following via console

Run this once

```
var xpathExists = (xpath) => !!document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

```

Then run this and if there is a matching XPath result it will return true

```
pathExists('//header/div//div[@class="flex gap-4 items-center"]/div[@class="relative hidden lg:inline-block mr-4"][1]/a')

```

Before moving this into your layout file be sure to prepend the XPath value with '/root'

Roadmap
-------

[](#roadmap)

- make module disable-able
- make log flag setable/env'able
- record blocks and output, with/without theme
- generate analysis report.
- make play nice with hyva when prod mode (ccs classes)
- unit tests
- coding standards
- initial release

**Potentials**

- profiler with autowarning when block takes excessive time?

SDS testing

enable with theme php bin/magento deploy:mode:set developer
&amp;&amp; php bin/magento cache:enable
&amp;&amp; php bin/magento cache:flush
&amp;&amp; git checkout app/design/frontend
&amp;&amp; php bin/magento dev:layout-xml-plus:collect --with-theme --clear

enabled without theme php bin/magento deploy:mode:set developer
&amp;&amp; php bin/magento cache:enable
&amp;&amp; php bin/magento cache:flush
&amp;&amp; php bin/magento dev:layout-xml-plus:collect --without-theme --clear
&amp;&amp; find ./app/design/frontend/ -type f -name '\*.phtml' -exec rm "{}" ;
&amp;&amp; git checkout app/design/frontend/z1/sds\_hyva/Magento\_Cms/templates/static-blocks/pagetop.phtml
&amp;&amp; git checkout app/design/frontend/z1/sds\_hyva/Magento\_Theme/templates/html/header/menu/C-desktop.phtml
&amp;&amp; git checkout app/design/frontend/z1/sds\_hyva/Magento\_Theme/templates/html/header/menu/C-desktop-item.phtml
&amp;&amp; git checkout app/design/frontend/z1/sds\_hyva/Magento\_Cms/templates/static-blocks/usps.phtml
&amp;&amp; git checkout app/design/frontend/z1/sds\_hyva/Magento\_Theme/templates/html/tradewidget.phtml
&amp;&amp; git checkout app/design/frontend/z1/sds\_hyva/Klaviyo\_Reclaim/templates/product/viewed\_hyva.phtml
&amp;&amp; git checkout app/design/frontend/z1/sds\_hyva/Hyva\_Checkout/templates/section/custom-summary-header.phtml

disable php bin/magento deploy:mode:set developer
&amp;&amp; php bin/magento cache:enable
&amp;&amp; php bin/magento cache:flush
&amp;&amp; git checkout app/design/frontend
&amp;&amp; php bin/magento dev:layout-xml-plus:collect --disable

Analyze php bin/magento dev:layout-xml-plus:analyse

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance80

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~69 days

Recently: every ~120 days

Total

10

Last Release

103d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b08c35b603becab270a53db6ec969f48be0c353a20ee2985bb1a8ec5a9b64e9?d=identicon)[zero1](/maintainers/zero1)

---

Top Contributors

[![adamzero1](https://avatars.githubusercontent.com/u/6369163?v=4)](https://github.com/adamzero1 "adamzero1 (14 commits)")[![arronmoss](https://avatars.githubusercontent.com/u/2673943?v=4)](https://github.com/arronmoss "arronmoss (2 commits)")[![bradley-zero1](https://avatars.githubusercontent.com/u/183477695?v=4)](https://github.com/bradley-zero1 "bradley-zero1 (1 commits)")[![callum-zero1](https://avatars.githubusercontent.com/u/22055276?v=4)](https://github.com/callum-zero1 "callum-zero1 (1 commits)")

---

Tags

magentomagento 2Zero1\_LayoutXmlPlus

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zero1-layout-xml-plus/health.svg)

```
[![Health](https://phpackages.com/badges/zero1-layout-xml-plus/health.svg)](https://phpackages.com/packages/zero1-layout-xml-plus)
```

###  Alternatives

[yireo/magento2-webp2

Magento 2 module to add WebP support to the Magento frontend

2091.2M7](/packages/yireo-magento2-webp2)[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[yireo/magento2-whoops

Magento 2 module adding Whoops error handling

102703.5k](/packages/yireo-magento2-whoops)[yireo/magento2-next-gen-images

Magento 2 module to add NextGen images support to the Magento frontend

471.1M2](/packages/yireo-magento2-next-gen-images)[goomento/module-page-builder

Goomento - The Free Magento Page Builder Extension, allows you to create unique Magento websites, landing pages using advanced animations, custom CSS, responsive designs, and more, without a line of code.

10413.0k2](/packages/goomento-module-page-builder)[yireo/magento2-integration-test-helper

Magento 2 module to support integration tests in other modules

1633.2k19](/packages/yireo-magento2-integration-test-helper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
