Magento - xml布局,为ifconfig指定值?
我确定我在某处看到过,为xml ifconfig语句指定一个值(因为默认值只是布尔值)。无论如何,禁用管理员模块并不实际工作(只禁用模块输出)。 但你可以ifconfig选项添加到您的布局文件,因此,例如,设置只有一个模块是禁用模板如下:Magento - xml布局,为ifconfig指定值?
<action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule">
<template>mytemplate.phtml</template>
</action>
那么你怎么能颠倒这一点,所以模板仅在模块为时启用?例如:
<action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule" value="0">
<template>mytemplate.phtml</template>
</action>
这很适合something(自我链接)我一直在努力。
如果没有课程改写来改变ifconfig
的行为,您无法完全按照您的要求进行操作。这是实现ifconfig
功能的代码。
File: app/code/core/Mage/Core/Model/Layout.php
protected function _generateAction($node, $parent)
{
if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {
if (!Mage::getStoreConfigFlag($configPath)) {
return $this;
}
}
如果检测到ifconfig的存在并且config值返回true,则不会调用操作方法。你可以重写_generateAction
并实现你自己的条件,但是保持重写的标准负担会让你失望。
更好的方法是在动作参数中使用辅助方法。这样
<action method="setTemplate">
<template helper="mymodule/myhelper/switchTemplateIf"/>
</action>
东西将调用与调用的结果setTemplate到
Mage::helper('mymodule/myhelper')->switchTemplateIf();
实现自定义逻辑switchTemplateIf
,要么保持模板或改变它,你会好到哪里去。
您可以单独创建一个单独的启用设置,只使用您的模块的system.xml
。
<config>
<sections>
<advanced>
<groups>
<YOURMODULE>
<fields>
<enable>
<label>YOUR MODULE</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_enabledisable</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enable>
</fields>
</YOURMODULE>
</groups>
</advanced>
</sections>
</config>
然后使用新的设置在布局文件:
<action method="setTemplate" ifconfig="advanced/YOURMODULE/enable">
<template>mytemplate.phtml</template>
</action>
是的,这就是我目前正在做的事情,这是行得通的,但如果使用默认的模块禁止器,会很好,并且不必将这个添加到每个布局。 – 2011-04-09 18:20:44
如何检查该字段的值.. => ifvalue =“....”...我想检查一个字段的值,然后决定在product_list的顶部或下方显示我的网格...谢谢... – 2011-07-06 05:47:37
@ime,目前在布局系统中没有'ifvalue',只有'ifconfig'来检查一个非零值。您可以使用一对是/否设置,一个用于'上面的产品列表',另一个用于'下面的产品列表'。 (这样可以让用户既可以打开也可以打开两个打开的文件) 唯一的另一种方法是自己编写PHP。 – clockworkgeek 2011-07-06 11:46:51
我只是想在layout.xml检查,检查现场,这是两个可能值的价值 - >顶部或 - >下方。因此,检查top是否被选中,然后在产品目录页面的product_list的下方显示我的产品top .. Thanx .. – 2011-07-06 05:59:45
我们可以调用helper方法而不是ifConfig,其中我们的自定义逻辑返回true或false。 – 2011-08-08 05:54:35
嗨艾伦,我们可以使用这种方法通过使用我们自己的模块的系统变量来设置某个Magento页面的模板布局吗?我为它开了一个新的问题。会很高兴,如果你能chekc它在这里http://*.com/questions/11593340/magento-changes-layout-dynamically-via-system-variable – Kamal 2012-07-21 15:18:24