When is the <body>
tag needed in layout XML, particularly when extending existing layouts?
The documentation provides examples where tags like <referenceBlock>
are contained inside <body>
, but it seems to work just as well when they are included directly under the root.
Documented style:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="something">
...
</referenceBlock>
</body>
</page>
Also seems to work:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="something">
...
</referenceBlock>
</page>
Per the XSD, only the former is allowed, but maybe Magento's logic just isn't strict about that?