更新时间:2023-11-29 23:21:22
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.