Jump to content

Archived

This topic is now archived and is closed to further replies.

flamerail

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

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 :)

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.