6
votes

I'm having some trouble getting a custom Reference block to work in Magento.

These are the steps I have taken:

Step 1

Created a new “Reference” block in page.xml

<block type="core/text_list" name="newreference" as="newreference"></block>

Step 2

Added a reference to this block in the place I want it to appear in the page (above the footer in 1column.phtml, 2columns-left.phtml, 2columns-right.phtml, 3columns.phtml)

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

Step 3

Added a reference to catalog.xml which tells Magento I want to output a template part (specialfooter.phtml) in the ‘newreference’ Reference block on Category pages

<reference name="newreference">
     <block type="core/template" name="specialfooter" template="page/html/specialfooter.phtml"></block>
</reference>

Step 4

Created ‘specialfooter.phtml’ in the page/html/ directory with a simple paragraph block to test.

And nothing happens.

The steps I have taken fit with my understanding of how Reference blocks work, but I could be wrong. I'm struggling to find any documentation, official or otherwise, or any previous SO questions which sheds any light on the subject.

I'm using Magento ver. 1.7.0.2.

Any help would be much appreciated.

2
The most likely issue is that you haven't cleared the cache so the node isn't loaded into you cached xml layout. Your steps seem correct.Peter O'Callaghan
Unfortunately, I'm well aware of the dreaded Magento cache and it's ability to catch out developers. I've tried both clearing and disabling the cache.john0514

2 Answers

6
votes

Don't you have forget a echo ? :

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

I was having the same problem and this seems to work for me.

This block in layout/page.xml

    <block type="page/html/new_newreference" name="newreference" as="newreference" template="page/html/new/newreference.phtml"/>

Can be referenced in a page eg. 1column.phtml in the template/page folder using:

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

Note the correlation between the "type" naming and "template" path and the "name" and "as" with the getChildHtml().

Using the same principle for a product page. This block in layout/catalog.xml

    <block type="catalog/product_new" name="catalogreference" as="catalogreference" template="catalog/product/new/catalogreference.html"/>

Can be referenced in template/catalog/product/view.phtml using:

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

Note both these examples are folder specific

If you want a block to use with a widget. Add this block in the appropriate reference block eg "content" or "head" in the relevant xml file eg. page.xml or catalog.xml:

    <block type="core/text_list" name="mywidgetblock" as="mywidgetblock">
       <label>My widget Block</label>
    </block>

NB: I don't understand the "type" declaration but it works?

In the admin panel CMS/Widget/Widget instance new or existing Layout Updates/ Block Reference find "My widget Block" from the drop down.

I'm new to Magento and it took a lot of trial and error to work this out so I hope it helps someone in the same situation.