Using AS
is never required.
You should always add a NAME
before adding an AS
AS
is an alias to NAME
to make it more readable.
It can be used in templates files (.phtml) in getChild
/ getChildHtml
methods, but it can't be used to reference the block in layouts file.
For exemple :
In a first module, you have this layout (simplified):
<page>
<body>
<block class="Vendor\Module\Block\Parent" name="vendor_module_parent" template="Vendor_Module::parent.phtml">
<block class="Vendor\Module\Block\Child" name="vendor_module_child" as="child" template="Vendor_Module::child.phtml">
</block>
</body>
</page>
-> In Vendor_Module::parent.phtml
:
Both $block->getChildHtml('vendor_module_child')
and $block->getChildHtml('child')
will work.
-> In another layout :
<page>
<body>
<referenceBlock name="vendor_module_child"> <!-- Working -->
</referenceBlock>
<referenceBlock name="child"> <!-- Not working -->
</referenceBlock>
</body>
</page>
Same for move
instructions.
Hope this helps.