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

Pass Variable to $this->getChildHtml(’Block_Name’);
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

I have a Loop

foreach($address as $_address){
.......
//I would like to pass $_address to a block that is included via getChildHtml()
// can i do this or do i need a helper?

$this->getChildHtml('Block_Name',$_address);
or
$this->getChildHtml('Block_Name')->setSomthing($_address); // ???
......
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
AndreusPT
Jr. Member
 
Total Posts:  15
Joined:  2008-07-25
 

maybe something like this:

echo $this->getChild('child_name')->setAddress($_address)->toHtml();
// or $this->getChildBlock('child_name')->...
 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

Thanks for your reply - first person to replay to almost any of my about 10 questions all over the forum… thanks - not working for me, but i will keep trying and tweaking

 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

What I really need to know is

If I am ‘including’ a block inside another block i.e. can the child block ‘inherit’ variable declared in the parent block and if the child block can how do i access those variables?
i really am struggling with this one :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

@AndreusPT
Thanks with a little playing around with what you sent i finally cracked it Much appreciated

$this->getChild('twg_delivery_times')->setData('address'$_address);
echo 
$this->getChildHtml('twg_delivery_times');

the variable $_address is now passed to twg_delivery_times block as the variable $address and can be called as $this->address in twg_delivery_times block

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 

hi

it was useful when there is no loop. if i am setting the child html variable in a loop only the first id is repeating in all the loop the variable value is not changin. i think some cache problem it is taking. how to rectifiy the problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 

hi

with child html we cannot set the variable of a child block in a loop. at that time it take the first chilhtml in the loop and put them to the all subsequent child htmls.

i got how to set the variable of a block from another block in a loop. we have to make a block separately for that purpose and call the blockhtml.

i have done this to get the bestsellers for each sub categories in a page.

changed the code in subcategory page:

<?php Mage::getSingleton('catalog/layer')->setData("currcategory", $_category); ?>
<?php echo $this->getBlockHtml('week_bestsellers2') ?>

then in bestseller page :
$category = Mage::getSingleton(’catalog/layer’)->getData("currcategory");

by this i was able to filter the bestsellers according to the subcategories.......

 
Magento Community Magento Community
Magento Community
Magento Community
 
Felle
Jr. Member
 
Total Posts:  23
Joined:  2009-04-15
Leipzig
 

$this->getChild(’BLOCK_NAME’)->toHtml() inset of $this->getChildHtml(’BLOCK_NAME’) solved cache the problem for me in a loop.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zuloo
Jr. Member
 
Total Posts:  5
Joined:  2009-12-14
 

use

<?php echo $this->getChildHtml('myblock',false); ?>

the second parameter tells the method not to use caching for this block - its default is true (= do caching)…

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