SEO-Board: Free, Fast and Search Engine Optimization Friendly Forum Script
»User: »Password:   Remember Me? 
Posted:  29 Apr 2005 13:35
Hello,

I am very interested in knowing more about the templating engine used in SEO-Board. I have recently started writing my own discussion board script and I am at the stage of implementing a templating engine.

Would you mind letting me know how it works and perhaps even an example or two of it in use.

Thankyou
Posted:  29 Apr 2005 15:23
It works as many other template engines. The templates are stored in files. Wherever the template needs to render info variables are used, example: {$user_name}
And then you need to load the template, set all vars that are needed to render the html, and then substitute all vars with their values. I've done this with php's eval function. I have a faster version, but it will be used in the next version.
Posted:  29 Apr 2005 15:29
Ok thanks.

But what code is involved?

Code:

function get_template($template_name)
{
  $tn = './skin/'.$template_name.'.htm';
  if (file_exists($tn))
  {
    $t = file_get_contents($tn);
    return "return <<<TMP\r\n<!-- START: $template_name -->\r\n{$t}\r\n<!-- END: $template_name -->\r\nTMP;\r\n";
  }
  else
    die("FATAL ERROR: File not found $template_name");
}


I found this function in ./code/skin.php but surely this isnt it...or is it?

Im already aware about initiating a template like so:

Code:

print eval(get_template('mainfooter'));


Is there anymore involved?
Posted:  29 Apr 2005 15:37
Ok actually dont worry about that question... I just done some testing and found out for myself that that is all thats involved for the basic template parsing.

But how are variable replaced... is there some sort of array in which they are set and then replaced....

By the way thanks for the help. The reason im asking is because im learning PHP and am very interested in templating engines.
Posted:  29 Apr 2005 16:09
Ok no worries... Ive figured it out.

Good luck with SEO-Board
Posted:  03 May 2005 11:40
This is a good way to do it but by no means the best i brang this up for attention before the od, boards got wiped, i can't wait to see the new one