phpBB Standalone Template Engine

Discussion forum for MOD Writers regarding MOD Development.
Locked
nanothree
Registered User
Posts: 262
Joined: Wed Dec 10, 2003 8:33 am
Location: Doncaster, UK
Contact:

phpBB Standalone Template Engine

Post by nanothree » Sat Apr 18, 2009 12:59 am

In my opinion phpBB has the best templating system i have used. Its so simple and does everything i want a template engine to do. I wanted to be able to use my template engine in my own projects but didnt want to use anything else from phpBB.

After about a year of putting it off i finally decided i would take the plunge and try and get it to work standalone. After doing it, it took about 30 minutes, im really annoyed i didnt do it earlier.

Here is how to do it, it should take you about 10 minutes.

Firstly for convenience sake, you need to get the related classes together.

These are template (includes/template.php) and template_compile(includes/functions_template.php).

Take both of these classes and put them into a single file (template.php). Make sure that you don't include the:

Code: Select all

if (!defined('IN_PHPBB'))
{
    exit;
}
  
This will stop the script. Since we are not using this class from within phpBB we will not have that constant defined.
Once these classes are together you need to make 2 changes to the code.
First find:

Code: Select all

$this->files_template[$handle] = $user->theme['template_id'];
  
and comment it out.
Finally find:

Code: Select all

phpbb_chmod($filename, CHMOD_WRITE);
  
imkingdavid wrote:in 3.0.6. Here's the line you should be looking for:

Code: Select all

phpbb_chmod($filename, CHMOD_READ | CHMOD_WRITE);
and replace it with

Code: Select all

//phpbb_chmod($filename, CHMOD_WRITE);
chmod($filename, 0777);  
Your standalone templating class is now ready. Use is exactly the same as in phpBB except that you need to output the template at the end of your script, as this is taken care of by page_footer usually.

index.php:

Code: Select all

include('classes/Template.php');

$template = new Template();

$template->set_custom_template('templates', 'default'); //this is important as it states where the template files are located

$template->assign_var('TITLE', 'Standalone phpBB Template Class');

$template->set_filenames(array(
    'body' => 'index_body.html'
));

$template->display('body');
 
The code above shows how to use the class. Nearly the same as inside phpBB but you must include the $template->set_custom.... line.

The template files in my example are held in a folder named 'templates'. The directory structure for my little example is as follows.

Code: Select all

/index.php
/classes/
/cache/
    template.php
/templates/
    index_body.html
    site_header.html
    site_footer.html    
By creating 'cache' folder the class caches the files for me, if its not there it simply doesn't do any caching

and my index_body.html looks like this:

Code: Select all

<!-- INCLUDE site_header.html -->
		<h1>{TITLE}</h1>
<!-- INCLUDE site_footer.html -->

I hope some one finds this useful.
Last edited by nanothree on Wed Jan 06, 2010 12:44 pm, edited 3 times in total.

User avatar
Raimon
Former Team Member
Posts: 12089
Joined: Tue May 30, 2006 5:31 pm
Location: Netherlands
Name: Raimon Meuldijk
Contact:

Re: phpBB Standalone Template Engine

Post by Raimon » Sat Apr 18, 2009 6:48 pm

Moved to mod writers discussion since it is related to coding ;)
Want a new website, new design of just phpBB installation / extensions visit http://www.raimon.nl

Lyr
Registered User
Posts: 2
Joined: Thu Jun 18, 2009 7:14 am

Re: phpBB Standalone Template Engine

Post by Lyr » Thu Jun 18, 2009 7:48 am

Hello.

I would like to add one advice from my own experience as "Template engine beginner who want to try this one for his portal and know very few about phpBB".


I had to replace this thing

Code: Select all

$template->set_custom_template('templates', 'default');
by this one

Code: Select all

$template->set_custom_template(PHPBB_TEMPLATES, 'default');
Otherwise it was unable to find the templates just looking for "templates" directory. PHPBB_TEMPLATES is defined in my entry point as the following

Code: Select all

...
$null = define('PORTAL_BASE_DIR', dirname($_SERVER['SCRIPT_FILENAME'])  );
...
// phpBB template engine informations
$null = define('PHPBB_ROOT_PATH', PORTAL_BASE_DIR.'/view');
$null = define('PHPBB_TEMPLATES', PHPBB_ROOT_PATH.'/templates');
Note that defining PHPBB_ROOT_PATH is mandatory (or so I understood).


Thanks nanothree for the explanation !

Bogey
Registered User
Posts: 419
Joined: Wed Sep 19, 2007 2:31 am

Re: phpBB Standalone Template Engine

Post by Bogey » Thu Nov 19, 2009 4:37 am

It took me a while to post this here but... thanks for posting this :D It was great

User avatar
stickerboy
Former Team Member
Posts: 7349
Joined: Mon Mar 29, 2004 2:27 pm
Location: Airdrie, UK (127.0.0.1)
Name: Kenny Cameron
Contact:

Re: phpBB Standalone Template Engine

Post by stickerboy » Thu Nov 19, 2009 3:25 pm

Indeed and bookmarked. Starting a new project and this will help me greatly. Was actually about to try and do it myself, just my luck that I find it today :) Cheers again.
I'm a web-designing code-decrypting tech-support musician
|| Twitter || Flickr || BandCamp || phpBB Snippets ||
Formerly known as cherokee red

nanothree
Registered User
Posts: 262
Joined: Wed Dec 10, 2003 8:33 am
Location: Doncaster, UK
Contact:

Re: phpBB Standalone Template Engine

Post by nanothree » Sat Nov 21, 2009 6:19 pm

no problem,

i'm glad its come to some use for you guys

User avatar
Sam
Former Team Member
Posts: 2082
Joined: Thu Jan 22, 2009 3:59 am
Location: Sacramento, CA
Name: Sam Thompson
Contact:

Re: phpBB Standalone Template Engine

Post by Sam » Sat Nov 21, 2009 9:43 pm

Nice topic, I will be starting a project in the coming months and I really wanted to use the phpBB template engine, but I was too lazy to go remove all the dependencies to the phpBB install. Thanks!

Bookmarked. :D

User avatar
imkingdavid
Former Team Member
Posts: 2664
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King
Contact:

Re: phpBB Standalone Template Engine

Post by imkingdavid » Sun Nov 22, 2009 8:16 pm

Definitely a great thing to know. Thanks for taking the time to figure this out. I may be using this on a few projects in the future. :D Bookmarked. :ugeek:
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

User avatar
John P
Registered User
Posts: 1232
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: phpBB Standalone Template Engine

Post by John P » Sun Nov 22, 2009 8:51 pm

Bookmarked!!
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
igorw
Former Team Member
Posts: 8025
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Re: phpBB Standalone Template Engine

Post by igorw » Sun Nov 22, 2009 9:17 pm

Thanks for sharing, bookmarked. ;)
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: phpBB Standalone Template Engine

Post by Nelsaidi » Sun Nov 22, 2009 11:08 pm

Thanks for sharing + Bookmarked, but noticed one thing:

Code: Select all

chmod($filename, 777);  
Should be

Code: Select all

chmod($filename, 0777);   
Reason: "To ensure the expected operation, you need to prefix mode with a zero (0): " - See http://uk2.php.net/chmod
Image
Click here to find out what eRepublik is.

nanothree
Registered User
Posts: 262
Joined: Wed Dec 10, 2003 8:33 am
Location: Doncaster, UK
Contact:

Re: phpBB Standalone Template Engine

Post by nanothree » Tue Nov 24, 2009 4:53 pm

thanks Nelsaidi, i've updated the original post with your fix.

thesilmister
Registered User
Posts: 5
Joined: Tue Jun 16, 2009 10:50 am

Re: phpBB Standalone Template Engine

Post by thesilmister » Mon Dec 14, 2009 5:12 am

I am having some serious problems with using the phpBB template parser in my own website, separate to phpBB.

Does anyone have the modified template.php file with a list of the required variables needed in order to execute the template engine.

Thank you.

squeek
Registered User
Posts: 173
Joined: Sat Jan 20, 2007 12:43 am

Re: phpBB Standalone Template Engine

Post by squeek » Mon Dec 28, 2009 9:45 pm

hello, not sure if this topic is still active but thought i'd post here anyway.
this is just what i have been looking for but ive encountered a problem

These are template (includes/template.php) and template_compile(functions/functions_template.php).

the line above doesnt make sense, i can find the (includes/template.php) but i cant find (functions/functions_template.php) because there is no directory called functions? i figured you were referring to the file functions_template.php in the includes folder so i tried using that. i found by using that file i couldnt find the lines below...

$this->files_template[$handle] = $user->theme['template_id'];

or

phpbb_chmod($filename, CHMOD_WRITE);

could someone please correct me and point me in the right direction. i really hope this helps me to get started and thanks for posting :)

User avatar
imkingdavid
Former Team Member
Posts: 2664
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King
Contact:

Re: phpBB Standalone Template Engine

Post by imkingdavid » Mon Dec 28, 2009 11:42 pm

squeek wrote:hello, not sure if this topic is still active but thought i'd post here anyway.
this is just what i have been looking for but ive encountered a problem

These are template (includes/template.php) and template_compile(functions/functions_template.php).

the line above doesnt make sense, i can find the (includes/template.php) but i cant find (functions/functions_template.php) because there is no directory called functions? i figured you were referring to the file functions_template.php in the includes folder so i tried using that. i found by using that file i couldnt find the lines below...

$this->files_template[$handle] = $user->theme['template_id'];

or

phpbb_chmod($filename, CHMOD_WRITE);

could someone please correct me and point me in the right direction. i really hope this helps me to get started and thanks for posting :)
You are correct, he is referring to includes/functions_template.php. For the first line, you were going to comment it out anyway, so if it's not there it shold be alright.

For the second one, they changed it in 3.0.6. Here's the line you should be looking for:

Code: Select all

phpbb_chmod($filename, CHMOD_READ | CHMOD_WRITE);
I hope this helps. :)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

Locked

Return to “[3.0.x] MOD Writers Discussion”

Who is online

Users browsing this forum: No registered users and 17 guests