简体   繁体   中英

injecting magento block to head via observed event

what magento frontend events can should I observe if I want the chance to inject blocks to the ("head" block) ?

and while in the observer's code, how do I check if the current layout has some handle (eg not_logged_in) set.

Give the

controller_action_layout_generate_blocks_after

event a try. The Layout object and its child blocks should be instantiated by the point that event fires.

There's only ever one Layout object, and you can grab the handles in play with

// get the layout->get the updates manager->get the handles
$handles = Mage::getSingleton('core/layout')->getUpdate()->getHandles();
var_dump($handles);

If you're working on front-end code and trying to stick to magento conventions, it's probably better to add a layout.xml file to your module, and use the layout file to add your blocks. It's less fun than figuring out something new though!

I appreciate the plug on the blog, but clockworkgeek is correct. The best way to accomplish this is to use a layout file to add the blocks you need. It is also possible for those blocks to change their own rendering behavior based on arbitrary code.

If there is a reason why you cannot use layouts, please elaborate a bit in your question and we'll be happy to help.

Thanks, Joe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM