| Home | Hotscript | Downloads  
Text Link Ads

Tutorial - PHP
Categories
Blog [2]
Communication [1]
Site Stats [3]
Skin/Template [2]
Timer & Counter [1]
Tools [3]
Tutorial - Photoshop
Categories
Graphics [5]
Special Effects [2]
Text Effect [2]
Download - PHP Scripts
myBloggie - D/L
Advanced Blog System
myBloggie's Home
myBloggie's Demo
user: guest
pwd: pass
myEvent
Dynamic Calendar with Events
Bloggielite
New Generation Blog
TNX?
Temperpedic
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 !!!


myWebland © 2003, 2004 myWebland Group
myWebland | wahsei | Contact Us | Privacy Statement