edit
You can achieve this using page/html_wrapper
default block. This block will render >all its child blocks without using a template and without using the call >getChildHtml()
.
if you are using core/template
block as your parent block, it is not good to think about avoiding getChildHtml()
method, since it is vastly using in lot of places in core Magento.
But if you are using custom block, there is a way to do this. The answer lies in core Magento itself. For example, if you look on the block Mage_Page_Block_Html_Wrapper
block class, you can see a method _toHtml()
.
protected function _toHtml()
{
$html = empty($this->_children) ? '' : trim($this->getChildHtml('', true, true));
if ($this->_dependsOnChildren && empty($html)) {
return '';
}
if ($this->_isInvisible()) {
return $html;
}
$id = $this->hasElementId() ? sprintf(' id="%s"', $this->getElementId()) : '';
$class = $this->hasElementClass() ? sprintf(' class="%s"', $this->getElementClass()) : '';
$otherParams = $this->hasOtherParams() ? ' ' . $this->getOtherParams() : '';
return sprintf('<%1$s%2$s%3$s%4$s>%5$s</%1$s>', $this->getElementTagName(), $id, $class, $otherParams, $html);
}
This method actually renders all its child block to html. Plus the all those blocks will come under a wrapper element(by default it uses div
). Similarly you can use this method in your custom block
<?php
class Namspace_Modulename_Block_Custom_Block extends Mage_Core_Block_Abstract
{
protected function _toHtml()
{
$html = empty($this->_children) ? '' : trim($this->getChildHtml('', true, true));
return $html;
}
}
Now if you put any number of block inside your custom block, it will automatically get rendered.
<layout>
<[HANDLE_THAT_YOU_NEED]>
<reference name="content">
<block type="your_block_reference/custom_block" name="some.name">
<!-- put any number of blocks here -->
</block>
</reference>
</[HANDLE_THAT_YOU_NEED]>
</layout>
There is another alternative method that you can use. Just simply put only one statement inside your custom block template
<div><?php echo $this->getChildHtml('',true) ?></div>
This will also do the trick