Based on this description of Magento 2's layout rendering, where is the remove tag implemented in Magento?

That is, in a Magento 2 layout handle XML, you can tell Magento not to render a block with code that looks like this

<referenceBlock name="product.info.media.image" remove="true"/>

It's not clear what the remove tag is doing. Where is this block removed? It it at the layout handle XML parsing stage? The reader/scheduler stage? The generation stage? Somewhere else?


Looks like both the container and block reader/scheduler


have code that looks something like this

    $containerRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);

    if ($containerRemove) {
    } else {
        $this->mergeContainerAttributes($scheduledStructure, $currentElement);

i.e., the readers look for references with remove blocks, and then schedule the remove.

The block itself is actually removed when the GeneratorPool does the initial build out of the layout structure

#File: vendor/magento/framework/View/Layout/GeneratorPool.php
foreach ($scheduledStructure->getListToRemove() as $elementToRemove) {
    $this->removeElement($scheduledStructure, $structure, $elementToRemove);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.