Reputation: 143
I am new learner of magento, I see some code like the following in the template xml file.
<reference name="top.menu">
<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
</reference>
What's the meaning of the name part in the reference and block part? Are there some differences between them? What's the meaning of the type part in the block part? If I want to use my own type and name, how can I do that? what's the using of them? thank you.
Upvotes: 1
Views: 283
Reputation: 2384
Name is the way to call it for later use. You can call your block in a phtml to render it with :
echo $this->getChildHtml('yourname');
You can use the name in reference too, if you want in another layout to change this block you'll make a reference to this layout thanks to its name
<reference name="yourname">
YOUR CHANGES HERE
</reference>
As you might have understood reference is the name of the block your change will impact. For instance if in my checkout I want to change the block named "right" to add an inner block :
<checkout_cart_index>
<reference name="right">
<block type="core/template" name="yourname" template="yourtemplate.phtml" />
</reference>
</checkout_cart_index>
Finally, the type, it's the path to the block files (php file of your module under its block directory).
Example type="catalog/navigation" refers to app/code/core/Mage/Catalog
/Block/Navigation
.php the name is module/path_to_block example if the Navigation.php file was in a sub folder named Menu you would had type="catalog/menu_navigation"
Upvotes: 2