<?php
 
//require the library:
 
require "Template.php";
 
 
 
$template = new Template();
 
$template->loadFile('template_file.html');
 
 
//Example 1: Assign some simple variables
 
$template->setVar("int_var", 999);
 
$template->setVar("string_var", "<B>H</B>ello ' \"word");
 
$template->setVar("boolean_var", true);
 
 
 
//Example 2: if else condition
 
$template->setVar("show_category", true);
 
 
 
//Example 3: assign an array
 
$fruits = array(
 
    0=> array(
 
                'type'=>'fruit_1',
 
                'name'=>'apple',
 
                'color'=>'green',
 
                'price'=>25
 
            ),    
 
    1=> array(
 
                'type'=>'fruit_1',
 
                'name'=>'banana',
 
                'color'=>'yellow',
 
                'price'=>1
 
            ),    
 
    2=> array(
 
                'type'=>'fruit_2',
 
                'name'=>'coconut',
 
                'color'=>'green',
 
                'price'=>250
 
            )            
 
);
 
$template->setVar("fruits", $fruits);
 
 
//Example 4: assign an object
 
class Person {
 
    function getName()  {
 
        return "Joe";
 
    }
 
    function getAge() {
 
        return 31;
 
    }
 
    function __toString() {
 
        $desc  = $this->getName()." (age ". $this->getAge().")";
 
        return $desc;
 
    }
 
}
 
$template->setVar("person", new Person());
 
 
 
//Compile and show template file.
 
$template->show();
 
?>
 
 |