1

I am converting an HTML template into Magento theme. Here I have to separate each blocks into custom static block files such as footermenu.phtml, tweet.phtml and copyright.phtml to call like,

<?php echo $this->getChildHtml('footermenu'); ?> 
<?php echo $this->getChildHtml('tweet'); ?> 
<?php echo $this->getChildHtml('copyright'); ?> 

After reading this blog tutorial, added a new block like the following but it is not appearing with my Magento 1.9.0.1

app/design/frontend/base/default/layout/local.xml

<?xml version="1.0"?>
    <layout>
        <reference name="root">
            <block type="core/text_list" name="newreference" as="newreference" translate="label">
                <label>New Reference</label>
            </block>
        </reference>
        <reference name="newreference">
            <block type="core/template" name="newreferenceblock" template="newreference.phtml" />
        </reference>
    </layout>

In app/design/frontend/base/default/template/page/2columns-right.phtml

<?php echo $this->getChildHtml('newreference') ?>

app/design/frontend/base/default/template/page/template/newreference.phtml

<h1 style="background-color:yellow">Hello New Reference!</h1>
  • from which position you want add this block <?php echo $this->getChildHtml('footermenu'); ?> <?php echo $this->getChildHtml('tweet'); ?> <?php echo $this->getChildHtml('copyright'); ?> ? – Amit Bera Sep 17 '14 at 18:31
  • @AmitBera Actually it is for splitting footer part. Same thing I need for other sections also.For example: ourservices, top sellers,etc. – devo Sep 17 '14 at 18:33
  • are yo want to show only home? – Amit Bera Sep 17 '14 at 18:33
  • @AmitBera No. I want to display this in all pages as common. – devo Sep 17 '14 at 18:34
  • @AmitBera If you don't mind, please explain both in your answer (showing only in home, in all pages). – devo Sep 17 '14 at 18:35
2

If you want add this blocks to home page then you need to add this template under cms_index_index hadler:

<?xml version="1.0"?>
    <layout>
    <cms_index_index> <!-- add home page handler for showing on home page -->
        <reference name="root">
            <block type="core/text_list" name="newreference" as="newreference" translate="label">
                <label>New Reference</label>
            </block>
        </reference>
        <reference name="footer">
            <block type="core/template" name="footermenu" template="page/template/footermenu.phtml" />
            <block type="core/template" name="tweet" template="page/template/tweet.phtml" />
    <block type="core/template" name="copyright" template="page/template/copyright.phtml" />
        </reference>
    </cms_index_index>
    </layout>

if want to show it at all pages then change handler cms_index_index to default

As your reference block name is footer then it need add code at footer.phtml

[Edit need] because getChildHtml() not exit for class render all chld phtml file of footer.phtml

<?php echo $this->getChildHtml('footermenu'); ?> 
<?php echo $this->getChildHtml('tweet'); ?> 
<?php echo $this->getChildHtml('copyright'); ?> 

More details at

http://www.magentocommerce.com/design_guide/articles/intro-to-layouts http://www.smashingmagazine.com/2012/11/30/introducing-magento-layout/

You have to put your child template files in app/design/frontend/[base]/[default]/template/

| improve this answer | |
  • Now the block is adding when I enable Template Path Hints but the page contents are not rendering here. – devo Sep 17 '14 at 18:50
  • can you put footer.phtml code? – Amit Bera Sep 17 '14 at 18:53
  • footer.phtml ...?> <?php echo $this->getChildHtml('footermenu'); ?> <?php echo $this->getChildHtml('tweet'); ?> <?php echo $this->getChildHtml('copyright'); ?> – devo Sep 17 '14 at 18:56
  • copyright.phtml <h1>Am from Copyright!</h1> – devo Sep 17 '14 at 18:57
  • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.