Magento Forum

How Do I Move $this->stuff() Into Other Templates
 
Scott
Guru
 
Avatar
Total Posts:  333
Joined:  2007-08-31
Northwest Ohio
 

I’ll be pretty straight forward, let’s say I want to merge account links with the main nav. I can’t simply move <?=$this->getChildHtml('topRightLinks')?> from header.phtml into top.phtml right? How would I pull this off?

$this refers to different objects inside different templates, am I right?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Each block has a name (defined by < block ... name="block_name" > in layout xml)
and most blocks have a child alias (defined by < block ... as="child_name" > in layout xml)

<?=$this->getChildHtml('child_name')?>
is used to simplify templates and make use of the layouts.

From your request it looks like you don’t really care about layouts structure.
In your case I would use just block name which is accessible from any template:

<?=$this->getLayout()->getBlock('block_name')->toHtml()?>

Which might be reduced to:

<?=$this->getBlockHtml('block_name')?>
in future releases.
 
Magento Community Magento Community
Magento Community
Magento Community
 
NickL
Sr. Member
 
Avatar
Total Posts:  188
Joined:  2007-08-31
 

@Moshe.

Your the Man.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

To expand on the question:

All the blocks extend Mage_Core_Block_Abstract. This class defined getChildHtml() method, which makes all blocks have it available.
So you do not need to redefine this specific method.
If you want to use layout XML structure, you would need to move < block .. as="topRightLinks" > from < block ... name="header" > to the block that uses top.phtml and you will be able to use it from the template with the same code

<?=$this->getChildHtml('topRightLinks')?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Scott
Guru
 
Avatar
Total Posts:  333
Joined:  2007-08-31
Northwest Ohio
 

Okay, that makes sense now smile

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