Magento – Layouts

Layout files are XML files that control the position of blocks.

Each module has a layout file that is in charge of updating that specific module layout.

e.g.


<reference name="content">
    <block name="giftregistry.list" type="mdg_giftregistry/list" template="mdg/list.phtml" as="giftregistry_list"/>
</reference>

Provide breakdown of each of the parts of the layout.xml syntax


With regards to the layout xml file, here are some thing to note:
There are three main nodes:

  1. handle – this appease directly after the layout (version: optional) node and will be either default (used for setting global blocks), or defined by the combination of __.
  2. reference – used to make references to a block. Useful for specifying nested blocks or modifying existing blocks.
  3. block – this node loads the block. This is achieved with the use of defined properties, which are specified through the following:
    1. type – The identifier of the block class. E.g., catalog/product_list actually refers to Mage_Catalog_Block_Product_List.
    2. name – an internal handle that is used by other blocks to reference this block.
    3. before/after – used for block positioning relative to another block. These properties will also accept a ‘-‘ (dash/hyphen) character to specify that the block should appear at the very top or very bottom.
    4. template – defines the .pthml file that will be used in rendering the block.
    5. action – a block type has a number of actions that are available to it. E.g., the page/html_head block has additional functionality for adding CS and Javascript.
    6. as – using this allows the specification of the unique identifier that will be used for calling the block from the template, such as calling a child block by using getChildHtml(‘block_name’).