I have a static page in which I call a dynamic block:
{{block type="custommodule/search" name="custommodule_search" template="custommodule/search.phtml" }}
In the layout file of my custom module I'm adding two children of my custommodule_search block:
<layout>
<default module="custommodule">
<reference name="custommodule_search">
<block type="custommodule/search_bysize" name="search_by_size" template="custommodule/search/by-size.phtml" />
<block type="custommodule/search_byvehicle" name="search_by_vehicle" template="custommodule/search/by-vehicle.phtml" />
</reference>
</default>
All I want is to be able to call these two blocks with this:
$this->getChildHtml('search_by_size')
or this:
$this->getChildHtml('search_by_vehicle')
anywhere in the template of the main dynamic block.
The problem is that they are shown only if the reference is not to "custommodule" but to "content", but this way they are showing in the beginning of the "content" block, not where I want….
Best Answer
Blocks instantiated by the
{{block}}
directive in can not be referenced from layout XML files.That is because they are instantiated during the processing of the
renderLayout()
step, which calls each blockstoHtml()
method.The layout XML is processed before that, during the execution of the
loadLayout()
step.To work around this, declare the child blocks without a parent block in the layout XML
Then, in your
custommodule/search
block template usegetBlockHtml()
instead ofgetChildHtml()
.