Monday, November 7, 2011

How to create PyroCMS v1.3.2 widgets ?

5:42 AM

 

A quick guide for creating new widget in PyroCMS.

1. Go through these folders
CMS_installed_folder -> system -> cms -> widgets

2. All these folders are for separate widgets.copy anyone. We’ll use it as reference to create a new widget.

3. Paste that folder in
CMS_installed_folder -> addons -> shared_addons -> widgets

4. Here suppose I copied “navigation” widget folder & pasted.

5. There is folder name “views” & a file named “navigation.php”

6. Two more files inside “views” folder ..named “display.php” & “form.php”. “Display.php” is for frontend

7 “form.php” is for control panel.

7. Every widgets should hav the above mentioned folder & files bt with the name according to ur requirement.

8. Now we edit the files in the folder we pasted.

9. Suppose we are displaying categories via this widget.

10. Rename the folder to ”category”.

11. Rename file navigation.php to category.php.

12. Open category.php in text editor.

clip_image002

13. Rename Widget_navigation to Widget_Category. The replaced text should contain the name of ur file u r editing & name must begin wid the capital letter.

14. ‘en’ , ‘pt’ ,’ru’ etc are the languages..so u can delete them except “en” . en is the English language..

15. Replace text ‘en’ => ‘navigation’ with ur widget name. ‘en’ => ‘category’ in title array.

16. Replace text ‘en’ => ‘Display a navigation group with a widget’ with ‘en’ =>’description of ur widget’.

17. Change value of $author,$website & $version as u wish.

18. image The $fields is the array of fields that will be appearing in the form for control panel & passing the value while calling a function.

Here, run function is for running the query. If input has been taken from form in the control panel ,then the parameters should be passed to the function with variable “$options” else it will be just run(). We fetch an array in $options from the from in control panel.

19. U hav to load the model file which contains the database query u require. Or u can create your own model with reference of old model. If u dnt want to create new model..u have to add a function that can return the require the data from database in it.

20. That function called from run function and returns the array data to run function.

21. Run function returns it to display.php & this file renders the content to front end.

22. Grab the array in display.php & use it to display the require contents.

To install the widget :

1. Goto admin panel.image

2. 

Content -> widgets -> drag & drop widgets from list to the available areas.

3. Copy the code {pyro:widgets:instance id=”3”} & paste it the front end html file where u wud like the widget’s content to be displayed.

For Code Visit our Github page:

https://github.com/organizations/semicolondevelopers

Tutorial by:
Prajwol Shrestha
Semicolon Developers

Written by

We are passionate programmers. Enjoying the rich platforms of Semicolon Family of Programming languages we are proud to call ourselves Semicolon Developers.

0 comments:

Post a Comment

 

© 2013 Echo "Semicolon Developers"; Kathmandu. All rights resevered @ Semicolon Developers Network Pvt. Ltd.. Designed by Templateism

Back To Top