I want to know the differences between this two functions. I understand the behavior of getChildHtml(). It returns the html of the block or all the blocks if you don´t pass any parameters. And I can see
getChildHtml($name, $useCache, $sorted)
getChildChildHtml($name, $childName,$useCache, $sorted)
at first sight I a $useCache param that I suposed is to use cache.
Let's say you're in the root block's phtml template file, and you have a simplified block structure that looks like this
root
left
promo_top
navigation
promo_bottom
center
right
From the root block's template file, to print the left block you'd use getChildHtml
.
echo $this->getChildHtml('left');
However, if for some reason you wanted to print the promo_top block in the root template, you'd have to do something like this
$left = $this->getChildBlock('left')
echo $left->getChildHtml('promo_top')
The getChildChildHtml
method allows you to do this sort of thing in one simple method call. Again, from the root template
echo $this->getChildChildHtml('left','promo_top');
So, the semantics are
If you look at the source code you can see that, ultimately, this method just wraps a call to getChildHtml
#File: app/code/core/Mage/Core/Block/Abstract.php
public function getChildChildHtml($name, $childName = '', $useCache = true, $sorted = false)
{
if (empty($name)) {
return '';
}
$child = $this->getChild($name);
if (!$child) {
return '';
}
return $child->getChildHtml($childName, $useCache, $sorted);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With