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

Next revision
Previous revision
tutorials:development:hello_world_page [2009/01/13 17:25]
jonyo created
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.
  
-**Requires Geo 4.0 or higher.**  The following is not possible in Geo 3.1 and earlier, because the functionality for an addon to display it's own page was added to the addon system in 4.0.+**Requires Geo 4.0.0** 
 + 
 +The following is not possible in Geo 3.1 and earlier, because the functionality for an addon to display it's own page was added to the addon system in 4.0.
  
   - In the **addons/** directory, create a new directory named "**hello_world**". <   - In the **addons/** directory, create a new directory named "**hello_world**". <
Line 13: 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 29: 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 37: 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. <
  
-This isn't the limit of what addons can do, to see everything addons can do get the example addon (should be a free addon in the client area). It demonstrates the use of tags, along with all of the other current abilities of addons. Plus, as long as you make your addon name unique enough (the addon's folder name), you shouldn't have to worry about having name conflicts with future addons.+This isn't the limit of what addons can do, to see everything addons can do get the example addon (should be a free addon in the client area). It further demonstrates the use of addon pages, along with all of the other current abilities of addons.
  
 ===== Alternate Page Display Methods ===== ===== Alternate Page Display Methods =====
  
 You are not limited to returning the text you want to be displayed on the page, below are some alternate things you can do. You are not limited to returning the text you want to be displayed on the page, below are some alternate things you can do.
- 
  
 ==== 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 56: 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 77: 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) ====
Line 99: 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 116: 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.1231867525.txt.gz · Last modified: 2014/09/25 16:55 (external edit)