First initialize template with something like this:
Code: Select all
$template = new Template($phpbb_root_path . 'templates/subSilver');
then you can use it. The only parameter to that function is path where tpl files are stored.
To show some tpl file you should assign handle to it, and then parse it. Like this:
Code: Select all
$template->set_filenames(array('body' => 'my_template.tpl'));
$template->pparse('body');
'body' is unique handle for tpl file. you can use anything you want as its name.
To assign some variables to template use this:
Code: Select all
$template->assign_vars(array(
'VAR1' => 'first variable',
'VAR2' => $second_variable
));
and in tpl use {VAR1} and {VAR2} instead. Variables should be assigned before pparse(). Once you assigned variable it can be used in all tpl files that will be shown by script after that.
If you want some code to be shown on certain condition in php script write something like this:
Code: Select all
if(...some condition...)
{
$template->assign_block_vars('switch_my_condition', array());
}
and in tpl file use this:
Code: Select all
<!-- BEGIN switch_my_condition -->
This code will be shown only if switch_my_condition is assigned with assign_block_vars
<!-- END switch_my_condition -->
If you want to use loops for items that repeat then use assign_block_vars (same as in previous example. actually its exactly the same - in previous example i assigned one loop so code inside switch is shown once). Use it like this:
Code: Select all
for($i=0; $i<count($some_array); $i++)
{
$template->assign_block_vars('my_loop', array(
'VAR1' => $some_array['some_variable'],
'VAR2' => 'This is interation ' . $i
));
}
and in tpl file use code like this:
Code: Select all
<!-- BEGIN my_loop -->
var1 = {my_loop.VAR1}
{my_loop.VAR2}
<!-- END my_loop -->
For more examples look in subSilver tpl files and phpBB php files. Simpliest example is faq.php and faq_body.tpl
...i hope my explanation is clear enough.