Create a new page

From FUDforum Wiki
Jump to: navigation, search

Follow the below steps to add a new page to FUDforum. This procedure can be used to extend FUDforum, for example, to add a blog, calendar, chat page or anything else you can think off.


Step 1: Define an action

Define an action by editing in the forum's src directory. For example, to create a page that will display Hello World, you need to add something like:

 case 'hi':	/* 'hi' in URL will invoke hallo.php */
	$_GET['t'] = 'hallo';

This will redirect index.php?t=hi (or index.php/hi/ if you are using PATH_INFO) to hallo.php.

The file hallo.php will be made up of

  1. source code from src/hallo.php.t,
  2. a template from thm/default/tmpl/hallo.tmpl; and
  3. translatable message definitions from thm/default/i18n/en/msg.

Step 2: Define source code

Create a file *.php.t in the forum's src directory that will define the page's business logic and variables. For our example, we will create src/hallo.php.t like this:

 /*{PRE_HTML_PHP}*/       <-- Include points
 $msg = 'Hello world';    <-- Define code and variables
 {TEMPLATE: HALLO_PAGE}   <-- Insert HTML code

HALLO_PAGE is a PAGE template (we will defined it in the next section).

PRE_HTML_PHP, POST_HTML_PHP and POST_PAGE_PHP_CODE and be ignored for now. They define where include files (*.inc.t) will be inserted.

Step 3: Define a template

The visual presentation (HTML) will be defined in a template. For our example, thm/default/tmpl/hallo.tmpl will look like this:

 {PHP_FILE: input: hallo.php.t; output: hallo.php;}

 {REF: security.tmpl}   <-- include templates we may need.
 {REF: header.tmpl}
 {REF: usercp.tmpl}
 {REF: curtime.tmpl}
 {REF: footer.tmpl}

 {PAGE: HALLO_PAGE}     <-- Define the HALLO_PAGE page.
 {TEMPLATE: header}     <-- Use a template from an included file
 {TEMPLATE: usercp}
 <div class="ctb">
    {VAR: msg}          <-- Reference variable in source file
 {TEMPLATE: curtime}
 {TEMPLATE: footer}
 {PAGE: END}            <-- End of PAGE definition

Note how {VAR: msg} is used to refer to a variable in the source file (src/hallo.php.t). Similarly, {MSG: msgkey} can be used to refer to a translatable message in the forum's thm/default/i18n/en/msg file.

Step 4: Build and test

All that is left to do is to rebuild your theme from the Theme Manager and to test your new page.

Personal tools