PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Andrey Nikishaev   Little PHP Templater   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: Little PHP Templater
Template engine that caches output
Author: By
Last change: add some
Date: 15 years ago
Size: 1,459 bytes
 

Contents

Class file image Download
<?php

include_once('templater.php');

/*

new Template(dir1,dir2) - create templater.
    Dir1 - Dir for templates.
    Dir2 - Dir for cache.
    By default Dir1='templates/', Dir2='cache/'

is_cached(tpl_name,tpl_time,tpl_hash) - checks lifetime of cache
    tpl_name - name of the template, situated in Dir1.
    tpl_time - cache lifetime. tpl_time set to -1 it's means that cache never die. If 0 or nothing, it's means that there isn't any cache.
    tpl_hash - string for separate one cache from another. For example: you have 2 articles one in english and second in spanish. But they are use one template. So you just need ti write is_cached(tpl_name,tpl_time,"en") and is_cached(tpl_name,tpl_time,"sp").

assign(nave_of_variable,value_of_variable) - Sets variable to template

fetch(tpl_name,tpl_time,tpl_hash) - render template.
tpl_name - name of the template, situated in Dir1.
    tpl_time - cache lifetime. tpl_time set to -1 it's means that cache never die. If 0 or nothing, it's means that there isn't any cache.
    tpl_hash - string for separate one cache from another. For example: you have 2 articles one in english and second in spanish. But they are use one template. So you just need ti write fetch(tpl_name,tpl_time,"en") and fetch(tpl_name,tpl_time,"sp").


*/
$tpl=new Template();
if(!
$tpl->is_cached('a.tpl',300,'a')) {
echo
"Cached";
$tpl->assign("agon","agon");
}
echo
$tpl->fetch('a.tpl',300,'a');