In controller, for some condition, I want to set another parent block instead of the declared one in the layout XML. The goal is to have a possibility to make checks in template file like this:
if ($this instanceof My_Module_Block_CustomBlock) {
// ... custom stuff in template ...
}
I have tried append my custom block in the layout, but parent block is still which was declared in layout XML. The appended block is shown as a child1 of parent block:
public function ConversationAction(){
// some condition:
$converation_id = (int) $this->getRequest()->getParam('id');
if (is_int($converation_id) && $converation_id > 0) {
// I want to set my parent block here instead of default registered in xml layout file
$this->loadLayout();
$block = $this->getLayout()->createBlock('MyModule/Conversation')
->setData('area', 'frontend')->setTemplate('customer/Conversation.phtml');
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
} else {
// ... default layout and block ...
$this->loadLayout();
$this->renderLayout();
}
}
Is it possible to change the root block from controller somehow ?