
TNX?
Temperpedic Trade Show Booths Wedding Invitations Plus Size Maternity Clothes
|
| PHP/MySQL Tutorial |
| |
| Creating template based website using phpBB templating engine |
| Written by : Sean |
| Date : 2004-07-01 |
[Back]
[Home] |
|
|
|
|
If you want to make a website based on template & you have a phpBB installed
in your website, you will be surprise how easy to make use of the phpBB
templating engine for that purpose. Even a begineer can create a template based
website !!
Assumptions used in this tutorial 1) installed directory
for phpBB ./forums 2) Skin/style used = subsilver 3) trained at least 1
hour on php scripting ..really ??
Why template ?
By using template, you can split your
script into to parts 1) HTML past which is used by php for formating 2)
php script
by seperating the 2, if you need to change the layout of your
site without change much on the scripting.. all you need do to is to open the
tpl or html ( whichever you want to name it ) file & change to the layout
that you want without disturbing the php portion.
How does it works
1st you need to have a template file or an html based file
eg :
| Code: |
<html> <head>
<title>{TITLE}</title> </head> <body>
{BODY} </body> </html> |
2nd you need to have a php script to do the following
1) Read the template file 2) Replace all {XXXX} with variables defined
in this php script. 3) Parse the processed data ( read from the template
file with embedded variable ) onto the web browser.
Why use phpBB to do
this
In order the read the template file, replace those between the { }
with variable & parse it to the browser you need to write a series of
complicated php scripts. In order to simplify the process there are classes or
functions available as open source eg : Fast Template engine...etc.
phpBB use the same concept as such it has built in classes written for
templating process. so why want to reinvent the wheel
I will show you
how simple to use phpBB built in templating classes to build your own template
based website
The Script - Step one !!
1) Build your
template .tpl file
eg:
| Code: |
<html> <head>
<title>{TITLE}</title> </head> <body>
{BODY} </body> </html> | save it as test.tpl in the forums/template/subSilver
directory
2) Create a php script to parse the output based on the
test.tpl Save it as test.php in the root directory
| Code: |
<?php
define('IN_PHPBB', true); // to ensure your
script works ! // $phpbb_root_path = './forums/';
include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path .
'common.php');
init_userprefs($userdata);
$template->set_filenames(array( 'test' =>
'test.tpl') ); // change this if you need to use another tpl or add more tpl files
//
$template->assign_vars(array( 'TITLE'
=> 'My First Template based Website',
'BODY' => 'Welcome to
My Website', ) ); //play around with the
variables //
$template->pparse('test');
?> | run the test.php
& TA DAAAA ! Your 1st script using template !!!
|
|
|