Magento include phtml file within another phtml file
Question
I am making a custom home page for my magento website in a phtml file named home_banner.phtml, which in turn i have referenced in the CMS->Pages->Home Page content by the following code
{{block type="core/template" template="theme/home_banner.phtml"}}
In my home_banner.phtml I have called tags/popular.phtml to display the popular tags.
<div class="last-posts-grid clearfix">
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('tag/popular.phtml')->toHtml(); ?>
</div>
However the tags are not being displayed even though the anchor tag which says "view all tags" id getting called correctly. The ul class="tags-list" is also visible in the page source but the tags themselves are not visible. Any suggestions?
Solution
you need change block type core/template
to tag/popular
<?php echo $this->getLayout()->createBlock('tag/popular')->setTemplate('tag/popular.phtml')->toHtml(); ?>
OR
give a name of block
{{block type="core/template" template="theme/home_banner.phtml" name="myname"}}
then
by using xml reference include tags/popular.phtml
create local.xml at app/design/frontend/youupackage/yourtemplate/layout
put this code
<?xml version="1.0"?>
<layout version="0.1.0">
<cms_index_index translate="label">
<reference name="myname">
<block type="tag/popular" name="home_tags_popular" template="tag/popular.phtml"/>
</reference>
</cms_index_index>
</layout>
and put below code at home_banner.phtml
echo $this->getChildHtml('home_tags_popular');