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

Move cart_sidebar to header
 
Allisone
Jr. Member
 
Total Posts:  15
Joined:  2011-03-14
 

I’m learning Magento Design

I copied checkout.xml into my theme and I’m editing what normally is

<reference name="right">
            <
block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
in Line 44

Now I found out that

<reference name="header"> doesn’t work
<reference name="top.links"> doesn’t work
<reference name="top.menu"> doesn’t work
<reference name="top.container"> works

doesn’t work = cart won’t be shown

Why is that ? Why can I put the cart_sidebar into top.container but not into top.menu, or top.links ?
I don’t say that this is what I need (actually I would need a hybrid of checkout_cart_link and cart_sidebar in the head), I’m just trying to understand the concept and how that stuff works.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagentoECG
Magento Team
 
Avatar
Total Posts:  189
Joined:  2011-02-25
Worldwide
 

Hi Allisone!

In short words:

<reference name="header"> doesn’t work

The reason, that the header block has own template and all children html should be called from that template
smth like:

// somewhere in template
<?php echo $this->getChildHtml('cart_sidebar'?>

----

<reference name="top.links"> doesn’t work

This block accepts only specific data format and can not be used as container for other blocks

----

<reference name="top.menu"> doesn’t work

Can not say anything as it should work well. Probably you hadn’t refreshed the cache that time

----

<reference name="top.container"> works

Yeah, and the reason that block type “page/html_wrapper” is handling his children in

protected function _toHtml()
{
    $html 
= empty($this->_children) ? '' trim($this->getChildHtml(''truetrue));
    
/// ***

Good luck,

Kor

 
Magento Community Magento Community
Magento Community
Magento Community
 
Allisone
Jr. Member
 
Total Posts:  15
Joined:  2011-03-14
 
MagentoECG - 14 April 2011 10:06 AM

<reference name="header"> doesn’t work

The reason, that the header block has own template and all children html should be called from that template
smth like:

// somewhere in template
<?php echo $this->getChildHtml('cart_sidebar'?>

Works now… So to rephrase. If I want to hook a Block MY into another Block X that has a type attribute that references an existing template file, then I need to (1.) reference Block X in Block MY and (2.) add a

<?php echo $this->getChildHtml('cart_sidebar'?>
Call somewhere in that template file referenced by Block X’s type attribute ?!
----
MagentoECG - 14 April 2011 10:06 AM

<reference name="top.links"> doesn’t work

This block accepts only specific data format and can not be used as container for other blocks

How do I know such things ? Is there a pattern ?
----

MagentoECG - 14 April 2011 10:06 AM

<reference name="top.menu"> doesn’t work

Can not say anything as it should work well. Probably you hadn’t refreshed the cache that time

You were right
----

MagentoECG - 14 April 2011 10:06 AM

<reference name="top.container"> works

Yeah, and the reason that block type “page/html_wrapper” is handling his children in

protected function _toHtml()
{
    $html 
= empty($this->_children) ? '' trim($this->getChildHtml(''truetrue));
    
/// ***

So is this the default behaviour that allows that referencing of blocks described in http://www.magentocommerce.com/design_guide/articles/intro-to-layouts#head-rules-of-XML ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
uguptu
Sr. Member
 
Avatar
Total Posts:  125
Joined:  2010-02-01
Kyiv, Ukraine
 

More correctly, there are two types of blocks:

1. Ones derived from Mage_Core_Block_Abstract with overridden _toHtml(). They don’t use template for their rendering. They do it as described in the _toHtml() method. Mage_Core_Block_Text_List is one of them, it does nothing but rendering its own children blocks. There are other of this kind that do quite different stuff.

2. Ones derived from Mage_Core_Block_Template. They respect the template property assigned to the block either by mentioning template="...” in the <block> layout update instruction, or by performing $this->setTemplate(’...’); in the so-called block pseudo constructor _construct(). To make such blocks render anything additional, you need to put some code into the template that will render and output the result, it’s usually <?php echo $this->getChildHtml('child_block') ?>.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Allisone
Jr. Member
 
Total Posts:  15
Joined:  2011-03-14
 

Thx, you helped me a lot :D

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