0

I'm creating a plugin, that is return an array. This how my files structure

myplugin.php

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

In the default.html file, I can access it via {{ myplugin:foo }}. Everything is working perfectly,

But I want to get second element of array. Or without using Lex Parser, How can I access via PHP?

KKK
  • 1,652
  • 7
  • 29
  • 49

1 Answers1

0

You need to pass it as a parameter to plugin. For example:

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

Then in your plugin:

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

That's all.

ReynierPM
  • 17,594
  • 53
  • 193
  • 363