Thursday, 21 January 2016

What are blocks in Magento

There are two types of blocks: those that automatically render their children and those that don't. Knowing which type you're using will help you in debugging.

Magento blocks are essentially models that contain logic for your view templates. Mind you - this is not business logic, but it is logic related to the display of the information you're presenting. This is by definition presentational logic. If you're familiar with Zend Framework's Zend_Layout you could draw a comparison between custom view objects and layout helpers.

The template file assigned to a block object can execute code as if it is local to that object. That is, $this corresponds directly to the block class.

Layout actions are a thing that people use.

Two types of blocks

There are two types of blocks at the end of the day - those that render automatically and those that don't. Take notes because this is on the Magento Certification exam!!

Auto-rendered blocks


When defined in a layout, any block of type core/text_list will automatically render all its children. While core/text will automatically render itself it really only should contain text and therefore is not useful for layout purposes (though some clever things can be achieved with them).



Other blocks


Any other block type will need to be rendered manually. Provide the block an alias which can then be passed to getChildHtml, returning the content which you then echo.

for more >>

No comments:

Post a Comment