KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm a front-end Magento dev, have built quite a few of my own themes and I want to understand Magento's XML block positioning better... I normally use a local.xml file to manipulate everything, I can define a block as follows: <cms_index_index> <reference name="root"> <block type="core/template" name="example_block" as="exampleBlock" template="page/html/example-block.phtml"/> </reference> </cms_index_index> This would create a block on the home page ( cms_index_index ) and since the block is created one level under root , I would normally call the block by adding: <?php echo $this->getChildHtml('exampleBlock') ?> ...to 1column.phtml (or 2columns-left / right.phtml , 3columns.phtml etc). The block can be placed on any page by substituting cms_index_index for the appropriate page tag. I see stuff like the following throughout the core XML files, and in tutorials: <reference name="root"> <block type="core/template" name="example_block" before="content" template="page/html/example-block.phtml"/> </reference> content is a block which is part of magento's general page structure and, from what I understand, before="content" should place it where you'd expect, without needing to use getChildHtml('exampleBlock') , so far so good... however, before/after hardly ever seems to work for me, and I frequently find myself resorting to the getChildHtml method as backup, which isn't always ideal, and means editing more .phtml files than necessary. I've tried: <reference name="root"> <block type="core/template" name="example_block" before="content" template="page/html/example-block.phtml"/> </reference>
Tags (comma-separated)
Save Edits
Cancel