Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Where is the content of <?php echo $this->getChildHtml(’left’) ?>
 
pdatoon
Sr. Member
 
Total Posts:  107
Joined:  2008-10-22
 

Hello guys,

I’m trying to re-organise my left sidebar. In the template (2columns-left), it calls : <?php echo $this->getChildHtml('left') ?>

Where can i find the content of this variable?

 
Magento Community Magento Community
Magento Community
Magento Community
 
gistya
Jr. Member
 
Total Posts:  8
Joined:  2014-02-21
 

I’ll actually answer your question instead of talking in riddles, how’s that:

So in Magento 1.4 I wanted to move the newsletter block so that it would appear below the related items block in the left column (instead of above it) I had to do this:

In the

<!--
Product view
-->

section of

app/design/frontend/shutterbug/default/layout/catalog.xml

I had to add at the beginning (of that section):

<!-- Remove the newsletter so we can re-add it again *afterthe related products-->
<
reference name="left">
    <
action method="unsetChild"><name>left.newsletter</name></action>
</
reference>
then just before the end (of that section):

<!-- Now add back the newsletter signup thingie-->
<
reference name="left">
    <
block type="newsletter/subscribe" name="left.newsletter" template="newsletter/subscribe.phtml"/>
</
reference>

and that was all that was required.

It’s necessary to do this because elsewhere,

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

says:

<reference name="left">
    <
block type="newsletter/subscribe" name="left.newsletter" template="newsletter/subscribe.phtml"/>
</
reference>

This makes the newsletter block get added to “left” prior to what happens in catalog.xml. Now, we know that “left” refers to the left column because in

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

we see on line 50:

<div class="col-left sidebar"><?php echo $this->getChildHtml('left'?></div>

The question that has been raised many times in various places (on the Magento forums, here, and elsewhere) is, “To what does ‘left’ refer to, here?” Because it’s not clear what it refers to. There is no “left.xml” in the “layout” directory, nor is there any clear place where the “col-left” or “left column” is clearly defined as a structure that one might rearrange.

Well, the thing is, “left” (in getChildHtml(’left’)) doesn’t refer to anything per se. It simply creates a reference, possibly to nothing, but probably to a structural block object. (Not confusing at all.)

So this reference (to nothing, maybe) gets created. What that means is that, later, you have to go in an tell Magento in your layout XML files that hey, for this reference “left”, add this here block type with this here template, by doing something like:

<reference name="myReferenceThatPreviouslyReferredToNothing">
    <
block type="foo/bar" name="asdf.bar" template="foo/bar.phtml"/>
</
reference>

That way Majento adds those content blocks to the object referred to. Of course this is very confusing. Why Magento does it this way is anyone’s guess; it’s a very powerful and object-oriented way of doing things, but I had to do some serious text searching to reverse engineer what they did here. It would have been much clearer if, (for the sake of clarity), their XML looked something like:

<addBlockToObjectByReferenceName name="left">
   <
blockToAddToThisReferredObject type="newsletter/subscribe" name="left.newsletter" template="newsletter/subscribe.phtml"/>
</
addBlockToObjectByReferenceName >

Haha but that would take more typing and without code completion to help you it would be a nightmare to program this way. But that’s what we’re doing here.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top