0

我正在创建一个插件,即返回一个数组。这就是我的文件结构

myplugin.php

class Plugin_myplugin extends Plugin
{
    function foo()
    {
       return array(1,2,3,4,5);
    }
}

在 default.html 文件中,我可以通过{{ myplugin:foo }}. 一切正常,

但我想获得数组的第二个元素。或者不使用 Lex Parser,我如何通过 PHP 访问?

4

1 回答 1

0

您需要将其作为参数传递给插件。例如:

{{ myplugin:foo pos="position" }}

然后在你的插件中:

class Plugin_myplugin extends Plugin
{
    function foo()
    {
       $pos = $this->attribute('pos');
       $arr = array(1,2,3,4,5);
       return $arr[$pos];
    }
}

就这样。

于 2014-06-17T19:32:28.400 回答