Sopily is a PHP Template Engine that is a good alternative of Smarty, it has following features:
- Use PHP syntax in template file, no template tags anymore.
- Execute template file directly, no compile anymore.
- Smarty methods include caching, assign, assign_by_ref, fetch, display and etc.
- Built-in Smarty's modifiers and functions with multiple syntax.
- Best performance.
It is easy and fast. Just try it.
Related link: 中文版介紹 http://dev.sopili.net/2009/04/sopily-php-template-engine.html
Demo
Main Script: index.php
$url='http://software.sopili.net/';
require_once('Sopily.class.php');
$sopily=new Sopily;
$sopily->template_dir="/home/www/sopily/demo";
$sopily->assign('url',$url);
$sopily->display('index_tpl.php');Template: index_tpl.php
<?
require('header_tpl.php'); //relative path, indicated by $sopily->template_dir
?>
<h1>Demo</h1>
url is <?=$url?> <br>
url with modifier <?=$_escape($url)?> <br>
url with multiple modifier: <?=sopily($url,Array('default'=>'http://www.sopili.net >_<|||','escape'))?> <br>
url with multiple modifier2: <?=sopily($url,'default','http://www.sopili.net')?> <br>
url with multiple modifier3: <?=$_escape($url)?> <br>
url with multiple modifier4: <?=$_escape($url,'html')?> <br>
<?
require('footer_tpl.php');
?>Benchmark
Get memory usage by memory_get_usage(). Get per requests time by apache benchmark. Scripts were modified from Demo file of Smarty.
| Methods\template | Sopily | Template Lite | Smarty |
| Memory (compiled/normal) | 707760 | 747496 | 992488 |
| Memory (Force Compile) | 707760 | 1345944 | 1952440 |
| Memory (Cached) | 251544 | 447688 | 584768 |
| Time per request (Cached) | 7.734 | 12.922 | 14.891 |
| Time per request (compiled/normal) | 37.118 | 48.438 | 46.719 |
The structure of Sopily is simple, so it is the fastest one.