简体   繁体   中英

How to load pyrocms Plugin within the theme

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM