I’m trying to re-organise my right sidebar. In the template (2columns-right), it calls :
<?php echo $this->getChildHtml('right') ?>
Where can I find the content of this variable?
I’m trying to re-organise my right sidebar. In the template (2columns-right), it calls :
<?php echo $this->getChildHtml('right') ?>
Where can I find the content of this variable?
You will find in your layout.xml file from where everything comes.It would have list blocks under which call .phtml files and data comes from there.I hope you understand what I am trying to convey.
You can add your custom blocks over there like this.
A call to method
getChildHtml()
loads the HTML for the child block with the name which is passed to the method, so in this case we are looking for a child block named right.To determine where to find this child block we need to know which block is calling this method. I know that that particular call to the
getChildHtml()
method appears in the main page column template as right is one of the columns. So have a look in thepage.xml
layout file and search for the template file inside which you found the method call, you will find something like this:Using the
<reference>
tag in a layout file allows you to alter the targeted block, and the<action>
tag allows you to run a block method inside the block you are working with. So this section of layout sets the template inside the root block. From this we know that it is the root block calling thegetChildHtml()
method.Next lets look at where the root block is defined in the layout, it's in the same
page.xml
layout file, and should be right near the top:There is quite a lot defined in this block, but you can see that it is given the name root and defines quite a few child blocks. One of these child blocks is named right and it is this block whose HTML is being output by the
getChildHtml()
method. It is important to note the block type -core/text_list
. This is a special block type which means that when rendering out the HTML for this block using thegetChildHtml()
method, child blocks will also be rendered. If the block type waspage/html
like with the root block, every child block added to the right block would need it's owngetChildHtml()
method call, using this block type, you only need a call togetChildHtml('right')
and all child blocks will also be rendered.As you can see the right block is defined here but it is empty. This is because in exactly the same way as your have the tag referencing the root block (
<reference name="root">
) other layout files add child blocks to the right block by referencing the right block.So to finally answer your question (and hopefully inform a little along the way), you need to be looking in layout files other than
page.xml
for references to the right block, here you will find all of the child content output by thegetChildHtml()
method call.You can alter what is added to the right block in your own module layout file, or
local.xml
layout file if you are not creating a module. I briefly cover thelocal.xml
layout file in my answer here with example syntax to add new blocks and remove blocks added in other layout files.