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 Template Path Hints
  3. Magento: Adding an RSS Feed
  4. Magento: Translate Inline
  5. Magento: PHTML Files In Dreamweaver

Tags: , ,

Leave a Reply


Contact Us Today...

If you have any questions about our services or want to arrange a free no obligation consultation contact us today or call 02920 290 080 for Cardiff and 01179 000 482 for Bristol.

Bit Torrent Study Discovers Most File Sharers Are Now Monitored

Ever heard of torrents or used Bit Torrent to download movies, music or shared files over the internet? Researchers have discovered that anyone who does use Bit Torrent to download files over the World Wide Web will most probably be monitored. Studies were carried out by Birmingham University and they have discovered that if someone [...]
» more

Cardiff: 02920 290 080 Bristol: 01179 000 482