快速和强大的PHP模板引擎:tonic

n7w77 10年前

快速和强大的PHP模板引擎,能够编译成原生PHP代码。

用法

Usin

$tpl = new Tonic();  echo $tpl->load("demo.html")->assign("user_role","member")->render();

Tonic is pretty straight forward.
$tpl = new Tonic("demo.html");  $tpl->user_role = "member";  echo $tpl->render();

It's also very flexible. The above code can also be written like:

Show me the syntax

Using Tonic

<body>  <h1>Bienvenido {$user.name.capitalize().truncate(50)}</h1>  Rol de usuario: {$role.lower().if("admin","administrator").capitalize()}  </body>

vs. writting all in PHP

<body>  <h1>Bienvenido <?php echo (strlen($user["name"]) > 50 ? substr(ucwords($user["name"]),0,50)."..." : ucwords($user["name"])) ?></h1>  Rol de usuario: <?php if(strtolower($role) == "admin") { echo "Administrator" } else { echo ucwords($role) } ?>  </body>

Caching

All tonic templates are compiled back to native PHP code. It's highly recommended that you use the caching functionality so that the same template doesn't need to be compiled over and over again increasing the CPU usage on server side.

$tpl = new Tonic();  $tpl->cache_dir = "./cache/"; // Be sure this directory exists and has writing permissions  $tpl->enable_content_cache = true; // Importante to set this to true!

项目主页:http://www.open-open.com/lib/view/home/1426772653836