Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates ExpressionEngine模板:传递插件/模块';s作为参数输出到另一个插件/模块_Templates_Expressionengine - Fatal编程技术网

Templates ExpressionEngine模板:传递插件/模块';s作为参数输出到另一个插件/模块

Templates ExpressionEngine模板:传递插件/模块';s作为参数输出到另一个插件/模块,templates,expressionengine,Templates,Expressionengine,以下是我想要实现的基本目标: {exp:plugin1:method arg="{exp:plugin2:method}"} 我尝试了许多不同的方法 方法1: 结果:Plugin1->method的arg参数值是字符串,{exp:plugin2:method},它从未被解析 方法2: 我对解析顺序的理解表明,这可能会产生不同的结果,但显然不会 {preload_replace:replaced="{exp:plugin2:method}"} {exp:plugin1:method arg="{

以下是我想要实现的基本目标:

{exp:plugin1:method arg="{exp:plugin2:method}"}
我尝试了许多不同的方法

方法1: 结果:
Plugin1->method
arg
参数值是字符串,
{exp:plugin2:method}
,它从未被解析

方法2: 我对解析顺序的理解表明,这可能会产生不同的结果,但显然不会

{preload_replace:replaced="{exp:plugin2:method}"}
{exp:plugin1:method arg="{replaced}"}
结果:参数
arg
的值与方法1相同

方法3: 首先,我定义一个代码段(
snip
),其内容是:

{exp:plugin2:method}
然后在模板中:

{exp:plugin1:method arg="{snip}"}
结果:与方法1和2相同

方法4: 注意到插件是按照它们出现的顺序进行处理的,我甚至测试了将
{exp:plugin2:method}
的一个实例放在
{exp:plugin1:method}
调用之前。我的想法是,我可以将第一个调用封装在一个regex替换插件中,以抑制输出,但它会首先触发Plugin2的解析

{exp:plugin2:method}
{exp:plugin1:method arg="{exp:plugin2:method}"}

结果:
Plugin1->method
arg
参数值是模板类保留到以后的
Plugin2->method
输出(我相信是MD5)的临时哈希占位符。

我有一个解决方法,但在我接受自己的答案之前,我会等待一段时间,看看是否有更好的解决方案。解决方法是使用
plugin2
包装
plugin1
,并替换引用
tagdata
中方法的模板标记。请注意,这需要在
plugin2
调用上使用
parse=“introw”
参数

在模板中: 在插件类中: 注意事项:
  • 这会使模板更混乱
  • 维护公共方法列表显然需要
    反射
    ,这在PHP4中是不可用的。当然,您可以手动维护预期方法的列表

    • 有趣的方法。但是,可以通过以下方式更简单地实现:

      {exp:plugin1:method arg="{exp:plugin2:method}" parse="inward"}
      

      事实并非如此,因为plugin1可能是一个已经定义好的插件,您无法编辑,而您是plugin2的所有者/编码者。至少我是这么想的,因为我在同样的情况下,最糟糕的是使用插件来实现这种行为。你可以为自己的目的创建一个模块,而不是强迫插件表现得不那么麻烦但又很简单。yi:如果你想在那里发布未来的EE问题,专注于EE的SE站点现在是公开测试版:@MediaGirl,谢谢你的提醒!
      {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();
      }
      
      {exp:plugin1:method arg="{exp:plugin2:method}" parse="inward"}