Magento: Create XML Blocks
Magento is a powerful e-commerce platform but has gained a reputation as being quite a bit of complicated kit. One area which has bugged me, is the static blocks and XML handles that you can use to create your own blocks of content.
After spending a while looking at how to create my own block, I have found a very simple method for including content from your own .phtml file that can be placed into whatever 1coloumn, 2columns-left, etc layout you wish.
By creating the a file eg: my_block.phtml and placing your content you wish to display within, it then needs to be put in a folder. I chose the page/html folder my for main template file to be placed.
Then in your page.xml file you need to create the handle to link to the .phtml file. Add the following where you want the .phtml to be retrieved. In my case under the content. eg:
<block type=”core/text_list” name=”content” as=”content” translate=”label”>
<label>Main Content Area</label>
</block>
<!— copy below —>
<block type=”core/template” name=”my_block” as=”my_block” template=”page/html/my_block.phtml”/>
Now, by placing this code: <?php echo $this->getChildHtml(’my_block’) ?> into the template files you wish eg: 1coloumn.phtml, it will now display on that specific template.
Related posts:







