这基本上就是我想要完成的事情:
{exp:plugin1:method arg="{exp:plugin2:method}"}
我尝试了很多不同的方法。
{exp:plugin1:method arg="{exp:plugin2:method}"}
结果: Plugin1->method
的{{1}}参数值是字符串arg
,它永远不会被解析。
我对解析顺序的理解表明,这可能会有不同的结果,但显然它没有。
{exp:plugin2:method}
结果:{preload_replace:replaced="{exp:plugin2:method}"}
{exp:plugin1:method arg="{replaced}"}
参数与方法1的值相同。
首先我定义一个代码段(arg
),其内容为:
snip
然后在模板中:
{exp:plugin2:method}
结果:与方法1和2相同。
注意到插件按照它们出现的顺序进行处理,我甚至在{exp:plugin1:method arg="{snip}"}
调用之前只测试了{exp:plugin2:method}
的实例。我的想法是,我可以在正则表达式替换插件中包装第一个调用以抑制输出,但它会首先触发Plugin2的解析。
{exp:plugin1:method}
结果: {exp:plugin2:method}
{exp:plugin1:method arg="{exp:plugin2:method}"}
的{{1}}参数值是Plugin1->method
输出的临时哈希占位符(我相信MD5),模板类保留直到晚些时候。
答案 0 :(得分:2)
有趣的方法。但是,这可以更简单地实现:
{exp:plugin1:method arg="{exp:plugin2:method}" parse="inward"}
答案 1 :(得分:0)
我有一个解决方法,但我会等待一段时间,看看在接受我自己的答案之前是否有更好的解决方案。解决方法是使用plugin1
包裹plugin2
并替换tagdata
中引用其方法的模板标记。请注意,这需要在parse="inward"
电话上plugin2
参数。
{exp:plugin2 parse="inward"}
{exp:plugin1:method arg="{someplugin2method}"}
{/exp:plugin2}
static $public_methods;
function __construct() {
// Actual construction code omitted...
if(($tagdata = $this->EE->TMPL->tagdata) !== false && trim($tagdata) !== '') {
if(!isset(self::$public_methods)) {
self::$public_methods = array();
$methods = get_class_methods($this);
foreach($methods as $method) {
if($method == get_class($this) || $method == '__construct') {
continue;
}
$reflection = new ReflectionMethod(get_class($this), $method);
if($reflection->isPublic()) {
self::$public_methods[] = $method;
}
}
self::$public_methods = implode('|', self::$public_methods);
}
$tagdata = preg_replace_callback('/\{(' . self::$public_methods . ')\}/',
array($this, 'tagdata_callback'), $tagdata);
$this->return_data = $tagdata;
}
}
private function tagdata_callback($matches) {
$method = $matches[1];
return $this->$method();
}
Reflection
。您当然可以手动维护一个预期方法列表。