Magento-XML布局,为ifconfig指定值? [英] Magento - xml layouts, specify value for ifconfig?

查看:141
本文介绍了Magento-XML布局,为ifconfig指定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定我之前在某处看到过,为xml ifconfig语句指定了一个值(默认情况下只是布尔值).无论如何,在管理员中禁用模块实际上不起作用(仅禁用模块输出). 的你可以ifconfig选项添加到您的布局文件,因此,例如,设置只有在模块是一个模板的停用与以下内容:

I'm sure I saw before somewhere, specifying a value for xml ifconfig statements (as default is just boolean). Anyways, disabling modules in the admin doesn't actually work (only disables module output). But you can add an ifconfig to your layout file, so for example, to set a template only if a module is disabled is the following:

<action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule">
    <template>mytemplate.phtml</template>
</action>

那么您怎么能反转它,因此只有在启用模块的情况下才可以设置模板?像这样:

So how could you invert this, so the template is set only if the module is enabled? Something like:

<action method="setTemplate" ifconfig="advanced/modules_disable_output/Myname_Mymodule" value="0">
    <template>mytemplate.phtml</template>
</action>

推荐答案

这非常适合

This fits in well with something (self-link) I've been working on.

没有类重写来更改ifconfig的行为,您将无法完全执行所需的操作.这是实现ifconfig功能的代码.

You can't do exactly what you want without a class rewrite to change the behavior of ifconfig. Here's the code that implements the ifconfig feature.

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,则不会调用action方法.您可以重写_generateAction并实现自己的条件,但是,保持重写的标准负担落在了您身上.

If the presence of an ifconfig is detected and the config value returns true, the action method will not be called. You could rewrite _generateAction and implement your own conditional, but then the standard burdens of maintaining a rewrite fall you on.

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

A better approach would be to use a helper method in your action paramater. Something like this

<action method="setTemplate">
    <template helper="mymodule/myhelper/switchTemplateIf"/>
</action>

将调用setTemplate通过调用

will call setTemplate with the results of a call to

Mage::helper('mymodule/myhelper')->switchTemplateIf();

switchTemplateIf中实施您的自定义逻辑,该逻辑既可以保留模板也可以对其进行更改,您将一路顺风.

Implement your custom logic in switchTemplateIf that either keeps the template or changes it and you'll be good to go.

这篇关于Magento-XML布局,为ifconfig指定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆