动态插入到Magento的布局xml中
我是Magento的新手。我正在尝试构建一个模块,在呈现代码xml之前将其动态插入到布局xml中- 类似于CMS>页面的构建方式 就像我们可以在页面admin>cms>页面的设计部分指定布局xml一样,我想通过我的模块插入layout.xml 基本上,我想 有一个管理部分,我可以通过 表单和存储在数据库中-我已经解决了这一部分 让Magento提取存储在数据库中的这些代码片段,并在聚集和解释布局文件之前创建一个xml文件。-我无法建造这部分。 任何帮助都将不胜感激。只是一点启示 您可以使用observer添加这些布局xml, 假设您希望在生成xml之前添加这些布局xml 我们可以使用事件控制器\u操作\u布局\u生成\u xml\u 下面是config.xml中的示例代码 只是一点启示 您可以使用observer添加这些布局xml, 假设您希望在生成xml之前添加这些布局xml 我们可以使用事件控制器\u操作\u布局\u生成\u xml\u 下面是config.xml中的示例代码动态插入到Magento的布局xml中,magento,Magento,我是Magento的新手。我正在尝试构建一个模块,在呈现代码xml之前将其动态插入到布局xml中- 类似于CMS>页面的构建方式 就像我们可以在页面admin>cms>页面的设计部分指定布局xml一样,我想通过我的模块插入layout.xml 基本上,我想 有一个管理部分,我可以通过 表单和存储在数据库中-我已经解决了这一部分 让Magento提取存储在数据库中的这些代码片段,并在聚集和解释布局文件之前创建一个xml文件。-我无法建造这部分。 任何帮助都将不胜感激。只是一点启示 您可以使用obs
另一种可能性是在事件发生后使用核心布局更新和占位符非现有布局xml:
<frontend>
<layout>
<updates>
<foobar>
<file>foo/bar.xml</file>
</foobar>
</updates>
</layout>
<events>
<core_layout_update_updates_get_after>
<observers>
<foobar>
<type>singleton</type>
<class>foobar/observer</class>
<method>coreLayoutUpdateUpdatesGetAfter</method>
</foobar>
</observers>
</core_layout_update_updates_get_after>
</events>
</frontend>
另一种可能性是在事件发生后使用核心布局更新和占位符非现有布局xml:
<frontend>
<layout>
<updates>
<foobar>
<file>foo/bar.xml</file>
</foobar>
</updates>
</layout>
<events>
<core_layout_update_updates_get_after>
<observers>
<foobar>
<type>singleton</type>
<class>foobar/observer</class>
<method>coreLayoutUpdateUpdatesGetAfter</method>
</foobar>
</observers>
</core_layout_update_updates_get_after>
</events>
</frontend>
<frontend>
<layout>
<updates>
<foobar>
<file>foo/bar.xml</file>
</foobar>
</updates>
</layout>
<events>
<core_layout_update_updates_get_after>
<observers>
<foobar>
<type>singleton</type>
<class>foobar/observer</class>
<method>coreLayoutUpdateUpdatesGetAfter</method>
</foobar>
</observers>
</core_layout_update_updates_get_after>
</events>
</frontend>
/**
* Event dispatched when loading the layout
* @param Varien_Event_Observer $observer
*/
public function coreLayoutUpdateUpdatesGetAfter($observer)
{
/** @var Mage_Core_Model_Config_Element $updates */
if (Mage::getStoreConfig('foobar/general/enabled')) {
$file = Mage::getStoreConfig('foobar/general/layout_xml');
if (!empty($file)) {
$updates = $observer->getUpdates();
if ($updates->foobar) {
$updates->foobar->file = $file;
}
}
}
}