我是Magento的新手.我试图建立一个模块,在渲染之前动态地将代码xml插入到布局xml中 - 类似于CMS>页面的构建方式.
就像我们如何在页面的设计部分(admin> cms> page)中指定layout xml一样,我想通过我的模块插入layout.xml.
基本上,我想
任何帮助,将不胜感激.
只需要一点启发您可以使用观察者添加这些布局xml,假设您希望在生成xml之前添加这些布局xml
我们可以使用活动 controller_action_layout_generate_xml_before
这是示例代码(in config.xml)
<frontend>
    <events>
        <controller_action_layout_generate_xml_before>
            <observers>
                <add_new_layout>
                    <class>test/observer</class>
                    <method>addNewLayout</method>
                </add_new_layout>
            </observers>
        </controller_action_layout_generate_xml_before>
    </events>
</frontend>
这是 Observer.php
public function addNewLayout($observer){
    $layout = $observer->getEvent()->getLayout();
    $update = $layout->getUpdate();
    //$action = $observer->getEvent()->getAction();
    //$fullActionName = $action->getFullActionName();
    //in case you're going to add some conditional (apply these new layout xml on these action or other things, you can modify it by yourself)
    //here is the pieces of layout xml you're going to load (you get it from database)
    $xml = "<reference name='root'><remove name='footer'></remove></reference>";
    $update->addUpdate($xml);
    return;
}
| 归档时间: | 
 | 
| 查看次数: | 1182 次 | 
| 最近记录: |