How to load pyrocms Plugin within the theme

123 views Asked by At

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?

1

There are 1 answers

0
ReynierPM On

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.