3

In Magento 1.9 I want to add a custom block to the homepage, but nothing happens. I have these files:

app/design/frontend/[mytheme]/default/layout/local.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <reference name="root">
            <block type="core/text_list" name="customblock" as="customblock" translate="label">
                <label>Custom Block</label>
            </block>
        </reference>
        <reference name="customblockreference">
            <block type="core/template" name="customblock" template="customblock.phtml" />
        </reference>
    </default>
</layout>

In homepage.phtml

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

in app/design/frontend/[mytheme]/default/template/customblock.phtml

<h1>test</h1>

Where am I doing wrong?

1
  • what is reference block name?
    – Amit Bera
    May 11, 2015 at 17:13

2 Answers 2

2

the problem is that you added reference with name "customblock", but then you try to append your custom block to "customblockreference" reference,

try to edit your reference code onto:

<block type="core/text_list" name="customblockreference" translate="label">
    <label>Custom Block</label>
</block>

it should work :)

BR,

Dmitry

1
  • Good answer.. but i am suggesting to you.If you will change handler from default to cms_index_index for only run at home page
    – Amit Bera
    May 12, 2015 at 10:31
0

You need to work at layout xml file:

As per as magento home page layout handler is cms_index_index

and you have called the custom block under default handler that means this block is called at all pages.

Also customblockreference should be homepage.phtml reference name:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <cms_index_index>
        <reference name="homepagephtmlRefeenceName">
            <block type="core/template" name="customblock" template="customblock.phtml" />
        </reference>
    </cms_index_index>
</layout>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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