Jump to content

Hows does phpbb load the template files and fill in the {}


flamerail

Recommended Posts

In phpbb it uses {blalblabla} as var areas in the templates. Hows does it load the template file and process it and load those with the wanted crap?

I dug thought the phpbb source code and found nothing that made sense as to that. Any ideas would be most welcome :)
Link to comment
Share on other sites

here's the short of it... obviously, it's a little more in-depth, but the basic idea is here. you create an array with the tag names and values that you want to substitute for the tags. for instance:

[code]
$tags = array(
  'TITLE' => 'My Page',
  'AUTHOR' => 'obsidian'
);
[/code]

now, you can set as many tags like this as you like. then, basically, you just load the template file into a string and run a str_replace() on all the tags and output the result. see if this continuation to the prep above helps make sense:
[code]
// set your tag values
$tags = array(
  'TITLE' => 'My Page',
  'AUTHOR' => 'obsidian'
);

$template = "This page is called \"{TITLE}\" and it was written by {AUTHOR}.";

// prep for your str_replace() call
$find = array();
$replace = array();
foreach ($tags as $key => $val) {
  $find[] = '{' . $key . '}';
  $replace[] = $val;
}

// replace it!
$out = str_replace($find, $replace, $template);
echo $out;
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.