php - Get custom phtml content using observer on core_block_abstract_to_html_after event -
i have custom block append under existing core block in order view page in admin panel of magento.
i developed custom module.
in order avoid modification of core template phtml file load custom block, try follow best practices , built observer on core_block_abstract_to_html_after
if want know why read more 2 excellent articles above
http://www.atwix.com/magento/best-practices/
http://inchoo.net/magento/how-you-could-build-your-magento-extensions-without-view-files/
however while block, want append, contain lots of html want put html in custom phtml file , not directly in php, make more customizable designers.
i created phtm file in following folder
app\design\adminhtml\default\default\template\custommodulefolder\customhtmlfileforadminorderview.phtml
but how load phtml content observer ?
<adminhtml> <events> <core_block_abstract_to_html_after> <observers> <custommodule> <class>namespace_custommodule_model_observer</class> <method>renderblockcustomdadmin</method> </referencefield> </custommodule> </core_block_abstract_to_html_after> </events> </adminhtml>
and method in observer.php
public function renderblockcustomdadmin($observer = null) { if (!$observer) { return; } if ('order_info' == $observer->getevent()->getblock()->getnameinlayout()) { if (!mage::getstoreconfig('advanced/modules_disable_output/'.self::module_name)) { $transport = $observer->getevent()->gettransport(); // here find way load content of custom of phtml $htmfromablock= function_which_will_allow-me_to_get_content_phtmlfile() $transportoldhtml =$transport->gethtml(); $transport->sethtml($transportoldhtml.'<br />'.$htmfromablock); } } return $this; }
creating block easy when layout (it matter of calling createblock()
block type want , settemplate()
template want use).
, can layout block.
so in case :
$observer->getevent() ->getblock() ->getlayout() ->createblock('adminhtml/template') ->settemplate('custommodulefolder/customhtmlfileforadminorderview.phtml') ->tohtml();
Comments
Post a Comment