Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/custom.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jin Nguyen  >  Puja  >  examples/custom.php  >  Download  
File: examples/custom.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Puja
Template engine that compiles templates into PHP
Author: By
Last change:
Date: 10 months ago
Size: 1,073 bytes
 

Contents

Class file image Download
<?php 
ini_set
('display_errors','On');
// custom filter
class CustomFilter{
    
/* {{ {var}|url:{arg} }} */
    
function filter_urlize($var$arg null){
        
$var strtolower($var);
        
$var str_replace(' ','-',$var);
        
$var substr($var0$arg);
        return 
$var;
    }
    
/* {{ {var}|ext }} */
    
function filter_ext($var$arg null){
        return 
substr($var,-4);
    }
}
// custom tags
class CustomTags{
    
/* {% css_tag {val} %} */
    
function css_tag($val$arg null){
        return 
'&lt;link src="'.$val.'" /&gt;';
    }
    
/* {% js_tag {val} %} */
    
function js_tag($val$arg null){
        return 
'&lt;script src="'.$val.'?'.$arg.'"&gt;&lt;/script&gt;';
    }
}
include 
'../puja.php';
$tpl = new Puja;
$tpl->template_dir 'templates/';
$tpl->cache_dir 'cache/';
$tpl->custom_filter = new CustomFilter;
$tpl->custom_tags = new CustomTags;
$tpl->parse_executer 'eval';
$tpl->headers = array(
    
'tpl_file'=>'custom.tpl',
    
'php_file'=>highlight_file('custom.php',true),
);
$data = array(
    
'name'=>'puja is a template engine',
    
'file_name'=>'/path/to/puja.php',
);
$tpl->parse('custom.tpl',$data);
?>