0

In my one-col phtml I echo this

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

and in my local layout xml, I have this.

<layout>
    <default>    
        <reference name="nav">
             <block type="core/text_list" name="nav" template="nav.phtml" />
        </reference>
    </default>
</layout>

Am I missing a step? Why isn't this showing up?

1

Ok, your layout is declared a bit wrong. Firstly you are referencing a block with name nav but you are also trying to declare this block inside nav by referencing it. Layout names must be unique over the whole page, so you are effectively trying to declare a block inside itself.

Also you have declared a block of type core/text_list. The job of this block is purely to render out child blocks added to it, so think of it as a container for other blocks rather than a block which will have it's own content render. If you look at core layout files, you will never see a template defined for blocks of type core/text_list, you will just see these blocks referenced and child blocks added.

If you don't want to have child blocks of your block just change the type to either core/template, or page/html if it's the frontend, and add it to root as the parent (as you are calling getChildHtml() inside the root template):

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <block type="page/html" name="nav" template="nav.phtml" parent="root" />
    </default>
</layout>

If you want to have child blocks automatically render out then you need to add children to the core/text_list block you declare.

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="root">
            <block type="core/text_list" name="nav_parent">
                <block type="page/html" name="nav" template="nav.phtml" />
            </block>
        </reference>
    </default>
</layout>

You would then use a call to <?php echo $this->getChildHtml('nav_parent') ?> in your root template which would render out the child block nav (and any other child blocks of nav_parent you added).

| improve this answer | |
  • I used the 1st example you provide and it works, thank you so much for such detail explanation. I think I understand much better about the relationship between layout and block. Thank you. – wlin Dec 13 '14 at 19:14
  • if I use the 1st example, I can't use $this->? can you briefly explain how $this came to be? and how to use it? I will open a question, and provide a link later. thanks for any help. – wlin Dec 19 '14 at 16:08
1

do you have somewhere the <block name="nav">?

| improve this answer | |
1

try this in your local.xml

<layout>
    <default>
        <reference name="root">
            <block type="core/template" name="nav" as="nav" template="page/navigation/nav.phtml" />
        </reference>
    </default>
</layout>

here you can find more details about block types used in layout : https://stackoverflow.com/questions/6633307/understanding-magento-block-and-block-type

hope that helps.

| improve this answer | |

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.