Jump to content


Photo

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


  • Please log in to reply
1 reply to this topic

#1 flamerail

flamerail
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 04 April 2006 - 07:49 PM

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

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 April 2006 - 08:13 PM

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:

$tags = array(
  'TITLE' => 'My Page',
  'AUTHOR' => 'obsidian'
);

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:
// 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;

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users