top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Difference between block’s “name” and “as” attributes in layout XML?

+2 votes
367 views
Difference between block’s “name” and “as” attributes in layout XML?
posted Aug 22, 2014 by Rajneesh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

here i can give brief understanding regarding magento block xml tag

name = Name of the block. It should be unique in the page.

*as = Alias *. Smaller form of name. It should be unique in it's parent block.

template = The template file (View) this block is attached to.

You can call methods from block type inside this by using $this.. e.g. $this->getName()

name vs. as example:

<reference name="left">
    <block type="block/blocktype1" name="first_block" template="template1.phtml">
       <block type="abc/abc" name="ty1" as="common" template="abc.phtml"/> 
    </block>
    <block type="block/blocktype1" name="second_block" template="template2.phtml">
       <block type="xyz/xyz" name="ty2" as="common" template="xyz.phtml"/>            
    </block>
</reference>

So, we can now call block name ty1 from first_block AND ty2 from second_block as $this->getChildHtml('common');, but see both the blocks called will be different as per their calling parent.

answer Sep 26, 2014 by Deepak Negi
...