Magento - xml布局,指定ifconfig的值?

Mar*_*ive 6 magento

我确定我在某个地方看到过,为xml ifconfig语句指定一个值(默认情况下只是boolean).无论如何,在管理中禁用模块实际上不起作用(仅禁用模块输出).但是您可以在布局文件中添加ifconfig,例如,仅在禁用模块时设置模板如下:

<action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule">
    <template>mytemplate.phtml</template>
</action>
Run Code Online (Sandbox Code Playgroud)

那你怎么能反过来,所以只有在模块启用的情况下才设置模板?就像是:

<action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule" value="0">
    <template>mytemplate.phtml</template>
</action>
Run Code Online (Sandbox Code Playgroud)

Ala*_*orm 22

这与我一直在努力的东西(自我链接)非常吻合.

如果没有类重写来改变行为,你就无法做到你想要的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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果检测到存在ifconfig并且config值返回true,则不会调用action方法.你可以重写_generateAction并实现自己的条件,但是保持重写的标准负担会让你失望.

更好的方法是在动作参数中使用辅助方法.像这样的东西

<action method="setTemplate">
    <template helper="mymodule/myhelper/switchTemplateIf"/>
</action>
Run Code Online (Sandbox Code Playgroud)

将调用setTemplate与调用的结果

Mage::helper('mymodule/myhelper')->switchTemplateIf();
Run Code Online (Sandbox Code Playgroud)

实现您的自定义逻辑switchTemplateIf,既可以保留模板,也可以更改模板,您将会很高兴.


clo*_*eek 9

您可以使用除模块之外的任何内容创建单独的启用设置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>
Run Code Online (Sandbox Code Playgroud)

然后使用布局文件中的新设置:

<action method="setTemplate" ifconfig="advanced/YOURMODULE/enable">
    <template>mytemplate.phtml</template>
</action>
Run Code Online (Sandbox Code Playgroud)