Magento - xml 布局,指定 ifconfig 的值?
我确信我之前在某个地方看到过,为 xml ifconfig 语句指定一个值(默认值只是布尔值)。无论如何,在管理中禁用模块实际上不起作用(仅禁用模块输出)。 但是您可以将 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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这与我一直以来的某事(自链接)非常吻合正在努力。
如果不重写类来更改
ifconfig
的行为,您就无法完全按照您的意愿行事。以下是实现ifconfig
功能的代码。如果检测到 ifconfig 的存在并且 config 值返回 true,则不会调用操作方法。您可以重写
_generateAction
并实现您自己的条件,但是维护重写的标准负担就会落在您身上。更好的方法是在操作参数中使用辅助方法。类似这样的事情
将调用 setTemplate,并返回在
switchTemplateIf
中实现自定义逻辑的调用结果,该逻辑要么保留模板,要么更改模板,然后您就可以开始了。
This fits in well with something (self-link) I've been working on.
You can't do exactly what you want without a class rewrite to change the behavior of
ifconfig
. Here's the code that implements theifconfig
feature.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
will call setTemplate with the results of a call to
Implement your custom logic in
switchTemplateIf
that either keeps the template or changes it and you'll be good to go.您可以只使用模块的
system.xml
来创建单独的 enable 设置。然后在布局文件中使用新设置:
You could create a separate enable setting using nothing but your module's
system.xml
.Then use the new setting in the layout file: