2

Take my example :

<block type="core/template" name="my.name" as="myName" template="path/to/template.phtml"/>

What purpose does the "as=myName" declaration serve. What abstract class defines these default attributes for layout handling?

ajameswolf
  • 1,650
  • 4
  • 21
  • 43

2 Answers2

3

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, you 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.

for detail class go throw this

Understanding Magento Block and Block Type

hope this will sure help you.

Community
  • 1
  • 1
liyakat
  • 11,825
  • 2
  • 40
  • 46
  • I understand all of that but you use the name if you want to do something like: is it purely an alias? a second name for easier recognition? – ajameswolf Sep 24 '13 at 14:57
  • before is tag to display block in priority.and you can use alias in before tag.pls dont forget to accept my answer.it would be glad for me and other user can use in future. – liyakat Sep 25 '13 at 03:36
1

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"/>