Login   Register  
PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of minh  >  Mini Fast Template  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example file how to use Template.php
Class: Mini Fast Template
Template engine that executes PHP template scripts
Author: By
Last change:
Date: 2011-04-19 01:32
Size: 1,205 bytes
 

Contents

Class file image Download
<?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();
?>