Anselme Anselme - 1 year ago 140
PHP Question

Get custom phtml content using observer on core_block_abstract_to_html_after event

I have a custom block that I would like to append under a existing core block in the order view page in the admin panel of Magento.

I developed my custom module.

In order to avoid modification of a core template phtml file to load my custom block, I try to follow the best practices and I built an observer on the


if you want to know why Read more two excellent articles above

However while the block, that I want to append, will contain lots of html I want to put this html in a custom phtml file and not directly in the php, to make it more easily customizable for designers.

I created so a phtm file in the following folder


But how to load this phtml content from the observer ?


And the method in my

public function RenderBlockCustomdAdmin($observer = NULL)
if (!$observer) {

if ('order_info' == $observer->getEvent()->getBlock()->getNameInLayout()) {

if (!Mage::getStoreConfig('advanced/modules_disable_output/'.self::MODULE_NAME)) {

$transport = $observer->getEvent()->getTransport();

// here I would like to find a way to load the content of a custom of phtml
$htmfromablock= function_which_will_allow-me_to_get_content_phtmlfile()
$transportOldHtml =$transport->getHtml();
$transport->setHtml($transportOldHtml.'<br />'.$htmfromablock);

return $this;

Answer Source

Creating a block is fairly easy when you get the layout (it is just a matter of calling createBlock() with the block type you want and setTemplate() with the template you want to use).
And you can always get the layout from another block.

So in your case :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download