When to use 'name' and when to use 'as'
Block can always be referenced by name
. Alias (as
) is used to simplify the long name of a block and the only differs with the scope. Name
has to be unique within the page and alias
within a parent block.
When you use as, you can call $this->getChildHtml("as_value") on the phtml template.
The name must be unique, and can be used for < reference > blocks, < remove >, etc.
For example (catalog.xml):
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
</block>
If you open catalog/product/view.phtml you'll see:
<div class="product-img-box">
<?php echo $this->getChildHtml('media') ?>
</div>
You see? as="media", and then $this->getChildHtml('media')...
Nobody has answered the particular question about unsetChild
yet. Methods related to children of a block always refer to child blocks by alias, which is only known to the parent and unlike the name, not globally unique.
But if the block was created without defining an alias, the alias defaults to the name.
So in short, if the child block has an explicit alias, you must use the alias. If not, use the name.
Aliases are given by as="..."
if the block was created as child block via XML, or by action parameter if they were moved around or dynamically added with methods like append()
, insert()
or setChild()
.