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:

  1. Install Magento Locally On A Mac
  2. Magento: Changing The Favicon
  3. Magento: Adding an RSS Feed
  4. Magento: Translate Inline
  5. Magento: PHTML Files In Dreamweaver

Tags: , ,

Leave a Reply

Contact Us Today...

For more information regarding any of our services or to arrange a free consultation simply send us a message or call 02920 290 080 for Cardiff and 01179 000 482 for Bristol.

Firefox 4 Beta

Mozilla have released the first beta version of Firefox 4. The latest version of this browser will include better support for many of the new web technologies, a new add on manager, crash protection from third party plugins and accelerated hardware support. One of the most obvious changes is that the tabs have now been moved [...]
» more

Cardiff: 02920 290 080 Bristol: 01179 000 482