Monday, April 9, 2012

Pyrocms - Step by step tutorial to create widget in pyrocms

Hi all, today i am going to tell you how to create a pyrocms widget in some easy steps. Widgets are a small program to show some text or some login form etc on your website. The widget we are going to develop in this tutorial, also outputs some simple text on sidebar. So here are the steps,


1. First you have to download and install pyrocms package from pyrocms website. You can do so by clicking here.

2. Now extract the package in your www folder of your wamp server and follow installation steps shown in installation wizard.

3. Next you have to create a folder in widgets folder. Let say we create a folder my_first_widget in widgets folder. In my case this is located here C:\wamp\www\pyrocms\addons\shared_addons\widgets\

4. Now you have to create a file called my_first_widget.php in my_first_widget folder. Be sure to use the same name as for your widget folder name. This is very must for your widget to work.

5. Next put following code in my_first_widget.php file and save it,

 <?php  
 class Widget_my_first_widget extends Widgets  
 {  
   //The following information will appear when you will install the widget  
   public $title = 'This is my first widget';  
   public $description = 'Puts default text.';  
   public $author = 'Asad Mehmood';  
   public $website = 'http://our-knowledge-base.blogspot.com/';  
   public $version = '1.0';  
 }  
 ?>  

6. Now you have to create a folder in my_first_widget folder and name it as "views".

7. Next create a file display.php in views folder and put following code in that file.

 <?php echo "This is my first widget"; ?>  

8. Now login to pyrocms admin panel and go to widgets section. Drag and drop my_first_widget widget in sidebar tray. Then refresh your front end page and see "This is my first widget" text displayed in sidebar.

Thats it, please feel free to post your comments and share this tutorial if you find this useful for you.
Thanks

20 comments:

  1. what!!! only that?
    This widget was so simple.
    yet i don't know what it was... :) @newbiealert

    ReplyDelete
    Replies
    1. yeah dear, creating pyrocms widget is very simple task to do. Purpose of my post is to show my blog readers, the basics of this.

      thanks for reading and commenting :)

      Delete
  2. i draged and droped already and click save after input title for this but this dont display at frondtend. Infact have no sidebar at frontend

    ReplyDelete
    Replies
    1. dear, did you follow all the steps mentioned in this post. I double checked this and this is working fine with me.

      Delete
  3. i'm missing something here because i don't see a wizard in the package linked in step 1.

    ReplyDelete
    Replies
    1. Dear loki, i have tested this on my laptop and its working fine with me. May be you have downloaded wrong package or something like this. can you test it again?
      Thanks

      Delete
  4. Hi Asad....your pluging...what it does ??
    Thans

    ReplyDelete
    Replies
    1. this plugin is showing how to create plugins in pyrocms. It displays a simple text at front end and by this way you will have better understanding of how to develop widgets in pyrocms. It can be customized to make it as you like.

      Delete
  5. Its working fine for me..thank you very much ir for this tutorial...glad if you can provide some more useful topics on pyrocms..

    ReplyDelete
  6. i want to put a module in widget ..how can i do this?

    ReplyDelete
  7. Thanks. was a good first basic step in learning PyroCMS.

    ReplyDelete
  8. How my_first_widget.php will associate with display.php? You haven't load view nevertheless it will work?

    ReplyDelete
  9. Hi asad,
    good post :)
    have an question.
    can i display the sample widgets only on certain pages in sidebar pyrocms.
    because my custom widgets are vary in different pages.

    Ex:
    In Video page , side bar widgets are "latest video comments" , "user navigation" , "latest upload videos"
    In blog page ,side bar widgets are "latest blog comments" , "user navigation" , "latest upload blogs"
    In music page ,side bar widgets are "latest music comments" , "user navigation" , "latest upload musics"

    Is it possible? Give me some examples .

    Thanx.
    vasa

    ReplyDelete
    Replies
    1. yeah there are different methods or techniques to achieve this. Best solution is to have separate layouts for each page and then display different widgets in different layouts

      Delete
    2. thnx for your quick comments :)
      If any possibilities to modify the different widgets in same layouts?

      Delete
    3. yeah you can do like this. set a variable in module or controller and then check that variable value in layout and display appropriate widgets

      Delete
    4. good and thnx keep rockz in pyrocms :)

      Delete
  10. Hi Asad Mehmood,

    Can you let mt know about, How to manage multi-language on front site with Pyrocms

    Second Question is -:

    How to connect module with another db, I mean i want to use external database with pyrocms site.

    Thanks.

    ReplyDelete

Please feel free to post your comments. If anyone has a good article or good thing to share, just send me that with your name to asadmehmoodstar@gmail.com. and if anyone want so receive updates regarding my blog, he can subscribe to my weekly newsletter on "Subscribe to our mailing list" section.

Thanks