User Tools

Site Tools


tutorials:development:hello_world_page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:development:hello_world_page [2009/01/16 23:34]
jonyo
tutorials:development:hello_world_page [2014/09/25 16:55] (current)
Line 1: Line 1:
 ====== Hello World using Addon Page ====== ====== Hello World using Addon Page ======
  
-This tutorial will walk you through the steps for creating an addon that will replace the **(!MAINBODY!)** (or **{body_html}** if using [[admin_menu/templates/template_system/start|file-based design]]) of a template with the text **Hello World**.  In other words, it allows you to make your addon display it's own page.  It works very similarly to [[tutorials/development/hello_world_tag|addon tags]], the difference is that this is for working with the main part of the page.  With a little modification, you can even make your addon create the whole page, instead of relying on an overall page template.+This tutorial will walk you through the steps for creating an addon that will replace the **{body_html}** of a template with the text **Hello World**.  In other words, it allows you to make your addon display it's own page.  It works very similarly to [[tutorials/development/hello_world_tag|addon tags]], the difference is that this is for working with the main part of the page.  With a little modification, you can even make your addon create the whole page, instead of relying on an overall page template.
  
 If you need your addon to display it's own page, use this tutorial as a starting point. If you need your addon to display it's own page, use this tutorial as a starting point.
Line 15: Line 15:
 //file /addons/hello_world/info.php //file /addons/hello_world/info.php
  
-class addon_hello_world_info { +class addon_hello_world_info 
- var $name = 'hello_world'; +
- var $version = '1.0.0'; + public $name = 'hello_world'; 
- var $title = 'Hello World'; + public $version = '1.0.0'; 
- var $author = "Hello World, Inc."; + public $title = 'Hello World'; 
- var $description = 'Displays "Hello World" page.'; + public $author = "Hello World, Inc."; 
- var $auth_tag = 'my_addons'; + public $description = 'Displays "Hello World" page.'; 
- var $pages = array (+ public $auth_tag = 'my_addons'; 
 + public $pages = array (
  'hello_world_page'  'hello_world_page'
  );  );
Line 31: Line 32:
 //file: /addons/hello_world/pages.php //file: /addons/hello_world/pages.php
  
-class addon_hello_world_pages { +class addon_hello_world_pages 
- function hello_world_page(){+
 + public function hello_world_page () 
 + {
  //Note: The method name matches the page name used in the $pages var in info.php  //Note: The method name matches the page name used in the $pages var in info.php
  return "Hello World!";  return "Hello World!";
Line 39: Line 42:
   - Now, go into addon management at [[admin_menu/addons/manage_addons/start|Addons > Manage Addons]], and you should see the addon named **Hello World**. Install and enable that addon. <   - Now, go into addon management at [[admin_menu/addons/manage_addons/start|Addons > Manage Addons]], and you should see the addon named **Hello World**. Install and enable that addon. <
   - There should now be a link for **Edit Page** for the Hello World addon.  Click on this link. <   - There should now be a link for **Edit Page** for the Hello World addon.  Click on this link. <
-  - On this page, select what template you want to use for your page, one template for every language you have defined, and save the changes.  Remember, using this tutorial the addon will be replacing the **(!MAINBODY!)** in the template. <+  - On this page, select what template you want to use for your page, one template for every language you have defined, and save the changes.  Remember, using this tutorial the addon will be replacing the **{body_html}** in the template. <
   - While still on the page, look for the **Link to Page**.  Click on the link to the right, and if everything was done correctly, you will see the page displayed, with the text "Hello World!" displayed on the main part of it. <   - While still on the page, look for the **Link to Page**.  Click on the link to the right, and if everything was done correctly, you will see the page displayed, with the text "Hello World!" displayed on the main part of it. <
  
Line 50: Line 53:
 ==== Display the Entire Page Yourself ==== ==== Display the Entire Page Yourself ====
  
-At the time the method is called in the pages.php file, nothing is displayed on the page yet, even if cache is turned on or if using [[admin_menu/templates/template_system/start|file-based design]].  This means, if you wanted to you could display the entire page yourself, by doing something like this for your **pages.php** file:+At the time the method is called in the pages.php file, nothing is displayed on the page yet, even if cache is turned on.  This means, if you wanted to you could display the entire page yourself, by doing something like this for your **pages.php** file:
  
 <code php> <code php>
Line 57: Line 60:
 //Alternate, to display the entire page //Alternate, to display the entire page
  
-class addon_hello_world_pages { +class addon_hello_world_pages 
- function hello_world_page(){+
 + public function hello_world_page () 
 + {
  //Note: The method name matches the page name used in the $pages var in info.php  //Note: The method name matches the page name used in the $pages var in info.php
 ?> ?>
Line 78: Line 83:
 }</code> }</code>
  
-When you use this method, you do not need to worry about setting the template for the page as described in **step 7** of the original instructions, since this method uses no templates.+When you use this method, you do not need to worry about setting the template for the page as described in **step 6** of the original instructions, since this method uses no templates.
  
 ==== Use Smarty Templates (Recommended) ==== ==== Use Smarty Templates (Recommended) ====
  
 Even though this is listed as an "alternate" display method, we actually recommend doing this for anything more simple than displaying something like "Hello World!" on the page.  We list this as an "alternate" display method, even though it is the one we recommend, in order to keep the main instructions as simple and easy to follow as possible. Even though this is listed as an "alternate" display method, we actually recommend doing this for anything more simple than displaying something like "Hello World!" on the page.  We list this as an "alternate" display method, even though it is the one we recommend, in order to keep the main instructions as simple and easy to follow as possible.
- 
-<tip c n>**Note:** You do **not** need to switch the site to use //File-Based Design// to use Smarty templates in your addon.  See [[admin_menu/templates/template_system/start#DB Based VS File Based Design]] for more info.  The part that applies most here is the last comparison point, //Addon's contents generated using..// in the linked comparison table.</tip> 
  
 For help creating Smarty templates, see the official [[http://smarty.net|Smarty.net]] website and [[http://smarty.net/manual/en/|their documentation]].  Have you read through the Smarty site and are ready to start using Smarty templates for your addon?  Good!  =)  Then follow the instructions below. For help creating Smarty templates, see the official [[http://smarty.net|Smarty.net]] website and [[http://smarty.net/manual/en/|their documentation]].  Have you read through the Smarty site and are ready to start using Smarty templates for your addon?  Good!  =)  Then follow the instructions below.
Line 102: Line 105:
  
 //extend our info class, so we can use $this-> to access vars in it //extend our info class, so we can use $this-> to access vars in it
-class addon_hello_world_pages extends addon_hello_world_info {+class addon_hello_world_pages extends addon_hello_world_info 
 +{
  
- function hello_world_page(){+ public function hello_world_page () 
 + {
  //Note: The method name matches the page name used in the $pages var in info.php  //Note: The method name matches the page name used in the $pages var in info.php
  //First, get instance of the view class  //First, get instance of the view class
Line 119: Line 124:
  }  }
 }</code> < }</code> <
 +  - Follow **step 7** from the original instructions above, to view your page.  If everything is working correctly, you should see the "Hello World!" text displayed on the page. <
  
  
tutorials/development/hello_world_page.1232148858.txt.gz · Last modified: 2014/09/25 16:55 (external edit)