Magento ::: How do I include a custom block in my templates?
I need to include a custom block on my templates, and even thoguh I read several instructions on how to do it, none seem to work, and none answer all issues (for me).
I have a template file here: [templates]/aw_blog/blog-bottom.phtml
I am using a custom theme according to best practices for Magento 1.4.1 and up, so I am working with local.xml to override the page.xml in the base theme.
In my 2column-left.phtml template, I call the blog-bottom templa开发者_开发知识库te like so:
<?php echo $this->getChildHtml('blog-bottom') ?>
So I know that the missing link is local.xml, but the various options I tried produce no results. So, what is the correct way to refer to this block in local.xml so that it is available to pages using 2column-left? I have both CMS and category pages using 2column left, and I'd want to show this block on all of them.
Thanks.
You're right, You have to add your block declaration in your layout xml. I don't use any local.xml file, I don't know what it is exactly, sorry :|
Anyway, if you want to add this block in, say, the left column you have to declare it this way (if the block named "left" is already declared)
<reference name="left">
<block name="customblock" type="core/template" template="path/to/your/template" />
</reference>
However, fOr this kind of block (which will be present on almost every page) I would rewrite the page.xml file and add the block directly in the declaration of the "left" block like this :
<block type="core/text_list" name="left" as="left" translate="label">
<label>Left Column</label>
<block name="customblock" type="core/template" template="path/to/your/template" />
</block>
精彩评论