Coding

Block types in Magento

Updated 3/25/11: TLDR; If you just want to make a block that displays the contents of a phtml file, use the block type core/template, like so


Then you can use $this->getChildHtml(‘logos’) in the relevant parent block to display it.

Original Post:
Block types are used in the layout XML files, ex,

Per this post, block types conform to the format “group/specific_class.”

For example Mage_Core module declares “core” group, which introduces blocks such as:
* “core/text” – simple block type to show text strings
* “core/template” – made for rendering templates into html

Each block type refers to specific class:
* “core/text” – Mage_Core_Block_Text
* “core/template” – Mage_Core_Block_Template

So, how it works that defining the block type essentially modifies the object you get with $this, which affects the data / methods you can use in that phtml template. Here’s a list of the more useful ones:

  • core/template – very simple, inserts the pthml file specified in the template attribute. Example, <block type=”core/template” template=”page.phtml”>

Leave a Reply

Your email address will not be published. Required fields are marked *