Today I am going to tell you how we can develop our own custom plug-in in pyrocms. In pyrocms whenever we edit some theme, or some view files, sometimes you will see some tags like {{ session:data name="foo" value="bar" }}. These are actually pyrocms plug-ins.
What is a plug-in?
In computing, a plug-in (or plug-in) is a set of software components that adds specific abilities to a larger software application.
In pyrocms there are two types of plug-in
- Standalone plug-in
- Modular plug-in
Standalone Plug-in:
Stand alone is a general plugin which is not necessarily dependent to other modules etc, like Google map, a simple twitter application etc. In pyrocms standalone plug-in are location in addons/plugins/.php
Modular plug-in:
Modular plug-in is actually a part of module which we already have developed. It actually adds more functionality in our existing module, that’s why it is located in the same module directory like addons/modules//plugin.php
How to develop this?
Create a file in addons/shared_addons/plugins/ directory with name example,php. And then put the following code in it and save.
1: <?php defined('BASEPATH') OR exit('No direct script access allowed');
2: /**
3: * Example Plugin
4: *
5: * Quick plugin to demonstrate how things work
6: *
7: * @package PyroCMS
8: * @author PyroCMS Dev Team
9: * @copyright Copyright (c) 2009 - 2010, PyroCMS
10: *
11: */
12: class Plugin_Example extends Plugin
13: {
14: /**
15: * Hello
16: *
17: * Usage:
18: * {{ example:hello }}
19: *
20: * @param array
21: * @return array
22: */
23: function hello()
24: {
25: $name = $this->attribute('name', 'World');
26: return 'Hello '.$name.'!';
27: }
28: }
29: /* End of file example.php */
How to use this?
Using this plugin is very simple. just put {{ example:hello }} tag in you them or in any view file and save it. By refreshing your page you will see "Hello World!" as output.
Please feel free to post your comments or queries.
oh thanks that helps me
ReplyDeleteSports Live News
you welcome dear :)
DeleteCan you please explain how to use array (single and multidimensional) in templates. Plugin function may return array also.
ReplyDeleteyea, we can handle arrays in pyrocms plugins. For this I wrote a post in my blog. You can read it by clicking on this url,
Deletehttp://our-knowledge-base.blogspot.com/2012/05/working-with-arrays-in-pyrocms-plugins.html