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

查看:21
本文介绍了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天全站免登陆