快速和強大的PHP模板引擎:tonic
快速和強大的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!
本文由用戶 n7w77 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!