通过观察事件将magento块注入头部

epe*_*leg 6 magento magento-1.4

如果我想有机会向("头部"块)注入块,我应该观察到什么magento前端事件?

而在观察者的代码中,我如何检查当前布局是否设置了一些句柄(例如not_logged_in).

Ala*_*orm 4

controller_action_layout_generate_blocks_after
Run Code Online (Sandbox Code Playgroud)

活动一试。布局对象及其子块应在事件触发时实例化。

只有一个 Layout 对象,您可以抓住其中的手柄

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

如果您正在处理前端代码并尝试遵守 magento 约定,那么最好将一个layout.xml 文件添加到您的模块中,并使用布局文件来添加块。但这并不比弄清楚新东西有趣!