Understanding more about magento block types
Tháng Một 8, 2013 Để lại bình luận
The available attributes for <block> are:
• type – This is the identifier of the module class that defines the functionality of the block. This attribute must not be modified.
• name – This is the name by which other blocks can make reference to the block in which this attribute is assigned.
• before (and) after – These are two ways to position a content block within a structural block. before=“-” and after=“-” are commands used to position the block accordingly at the very top or very bottom of a structural block.
• template – This attribute determines the template that will represent the functionality of the block in which this attribute is assigned. For instance, if this attributes is assigned ‘catalog/category/view.phtml’, the application will load the ‘app/design/frontend/template/catalog/category/view.phtml template file.
• as – This is the name by which a template calls the block in which this attribute is assigned. When you see the getChildHtml(‘block_name’) PHP method called from a template, it is referring to the block whose attribute ”as” is assigned the name ‘block_name’. (i.e. The method <?=$this->getChildHtml(‘header’)?> in the a skeleton template correlates to <block as=“header”> ).
•<reference> is used to make reference to another block. By making a reference to another block, the updates inside <reference> will apply to the <block> to which it correlates .
To make the reference, you must target the reference to a block by using the ”name” attribute. This attribute targets the <block> tag’s ”name” attribute. Therefore, if you were to make a reference by <reference name=“right”>, you are targeting the block named <block name=“right“>.
+ understand the meaning of
<block type="page/html" name="root" output="toHtml" template="example/view.phtml"> in Magento. ==>
A is a module’s alias. In this case
page is short for
Mage_Page_Block (it is defined in
app/code/core/Mage/Page/etc/config.xml if you want to see).
B is the class name relative to the alias, initial letters of each word are capitalised. In this case
Html and is appended to the resolved alias, so it is
Mage_Page_Block_Html. This is probably found in the file
app/code/core/Mage/Page/Block/Html.php because class names translate directly to locations in Magento.
Were you using a model alias instead of a block alias then
page would be
Mage_Page_Model instead. The same thing happens for resource models and helpers too. Your own module will need to define these in it’s config if it is to have blocks, models and helpers.
understanding more about magento block types following are some built-in block types which are widely used in layout.
core/template: This block renders a template defined by its
templateattribute. The majority of blocks defined in the layout are of type or subtype of
page/html: This is a subtype of
core/templateand defines the root block. All other blocks are child blocks of this block.
page/html_header: Defines the header part of the page which contains the site logo, top links, etc.
page/template_links: This block is used to create a list of links. Links visible in the footer and header area use this block type.
core/text_list: Some blocks like
rightetc. are of type
core/text_list. When these blocks are rendered, all their child blocks are rendered automatically without the need to call the
page/html_wrapper: This block is used to create a wrapper block which renders its child blocks inside an HTML tag set by the action
setHtmlTagName. The default tag is
<div>if no element is set.
page/html_breadcrumbs: This block defines breadcrumbs on the page.
page/html_footer: Defines footer area of page which contains footer links, copyright message etc.
core/messages: This block renders error/success/notice messages.
page/switch: This block can be used for the language or store switcher.
This is a list of only commonly used block types. There are many other block types which are used in advanced theme implementations.