Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP Template Engine

Very simple template engine for PHP Version 4 and 5. It is based on the article Beyond the template engine by Brian Lozier.

Example

<?php  
$path = './templates/';  

tpl = new Template($path);  
$tpl->set('title', 'User List');  
$body = new Template($path);  
$body->set('user_list', fetch_user_list());  
$tpl->set('body', $body->fetch('user_list.tpl.php'));  
echo $tpl->fetch('index.tpl.php');
?>

And it can be used with the following templates.

<!-- user_list.tpl.php -->
<table>  
    <tr>  
        <th>Id</th>  
        <th>Name</th>  
        <th>Email</th>  
        <th>Banned</th>  
    </tr>  
    <? foreach($user_list as $user): ?>  
    <tr>  
        <td align="center"><?=$user['id'];?></td>  
        <td><?=$user['name'];?></td>  
        <td><a href="mailto:<?=$user['email'];?>"><?=$user['email'];?></a></td>  
        <td align="center"><?=($user['banned'] ? 'X' : '&nbsp;');?></td>  
    </tr>  
    <? endforeach; ?>  
</table>

<!-- index.tpl.php -->

<html>  
    <head>  
        <title><?=$title;?></title>  
    </head>  
    <body>  
        <h2><?=$title;?></h2>  
        <?=$body;?>  
    </body>  
</html>   

About

Lightweight Template engine with the same interface as Savant3 and Smarty

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages