I have a 3rd party extension creating a block like so in block class:
class Namespace_Modulenam_Block_Custom extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
$this->setTemplate("amasty/amlanding/custom.phtml");
}
and assigning it to layout in a controller:
class Namespace_Modulename_PageController extends Mage_Core_Controller_Front_Action {
....
public function viewAction(){
....
$this->getLayout()->getBlock('content')->insert(
$this->getLayout()->createBlock(
'modulename/custom'
)
);
}
I just want to move the placement of the block (i.e. out of 'content', to a text/list block that i've created in a layout.xml file. If I edit this module to:
$this->getLayout()->getBlock('my_block')
the object is empty, presumably becuase the layout.xml defined block has not been created when the controller executes.
If i try adding a name to the block i.e.
$this->getLayout()->getBlock('content')->insert(
$this->getLayout()->createBlock(
'modulename/custom',
'my_name'
)
);
}
I can't edit it in layout.xml. So to test:
<remove name='my_name'/>
...does nothing.
What is the correct method to interact with this dynamic block? Should I be using event observers? Is there a simple way to do this in my layout.xml?
EDIT BASED ON fschmengler's ASNWER:
I've implemented fschmengler's solution and I am successfully assigning the block name and then unsetting it from the 'content' block.
However in Step2, moving the block:
$layout->getBlock('name.of.new.parent')->append(
$layout->getBlock('modulename.custom.name')
);
gives Call to a member function append() on a non-object
this would be because (as you fschmengler points out), this parent block is presently defined in layout.xml:
<reference name="root">
<block type="core/text_list" name="name.of.new.parent" as="name.of.new.parent" translate="label" />
</reference>
Do I need to define this block parent block in another way?