Hi everyone, following on from the previous posts, I have now extended the tutorial to bring you handy knowledge about Structure of block templates. Please keep carefully reading this reference for your using of Magento.
This article covers two contents:
- Define root template, non-output block
- Describe how to remove a child block from the template page
1. Define root template, non-output block
– Root template
Page.xml – root layout
– Root template will be declared as below:
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
Root templates can be the following files:
– Non-output block
• Non-output block only contains other blocks and cannot be used to render html (left, right, content)
• getChildHtml($name, $useCache, $sorted)
• getChildChildHtml(($name, $childName,$useCache, $sorted)
- $name: block’s name (If you leave blank, all blocks are rendered)
- $useCache: (If true, cache will be used)
- $sorted: (If true, child blocks will be rendered in the order of layout)
- $childName (option)
• getBlockHtml($name) (getBlock’s html may not be child block and call whatever blocks)
2. Describe how to render a root template
– In the default theme, “root block” is an “output block”
– Definitions in file page.xml
– Template attributes: 1column, 2 column-left, 2 column-right, 3 column (default).
– Child blocks are: head, header, breadcrumbs, left, right, content, footer.
– Render child blocks by calling $this->getChildHtml(‘header’);\
– The process of rendering is called recursively: root block comes first, then the child block, and so on.
3. Describe how to remove a child block from the template page.
– Removing a child block in the layout.
<remove name="" />(Completely remove all child blocks in a handle) <action method="unsetChild"> >(The child block can be called back in another block)
I hope you have enjoyed this blog and find it useful – thank you for visiting Magestore Blog.