en: This library is a easy & lazy & fast to help you building Smarty views in Codeigniter.
You can use this library to substitute Codeigniter-Parser library, or direct use Smarty build-in function to write your web application.
zh: 這個類庫是一項可以讓你在 Codeigniter 之中, 簡單、懶惰、快速 的 Smarty 樣版引擎建置方法。
你可以直接使用這個類庫取代內建的 Codeigniter-Parser 類庫來使用它,或是直接使用傳統的 Smarty 內建函式使用它。
-
Go http://www.smarty.net/ and download Smarty library.
-
Extract Smarty zip file into your third_party dir like a example:
/application/third_party/Smarty-3.1.11/Example path
/application/third_party/Smarty-3.1.11/demo/application/third_party/Smarty-3.1.11/libs/application/third_party/Smarty-3.1.11/change_log.txt/application/third_party/Smarty-3.1.11/COPYING.lib/application/third_party/Smarty-3.1.11/README -
Get this library into dir:
/application/libraries/template.php
in Controller
<?php function index() { // You also can setting autoload in /application/config/autoload.php $this->load->library( 'template' ); // Such as traditional syntax $this->template->assign( 'title', 'CI-Smarty Example' ); $this->template->assign( 'keyword', 'codeigniter,smarty,template' ); $this->template->display( 'home/index', $assign ); // default file ext is `.html` }
in HTML
<!DOCTYPE HTML> <html> <head> <title>{$title} - website name</title> <meta name="keywords" content="{$keyword}"> </head>
in Controller
<?php function index() { $this->load->library( 'template' ); $data['title'] = 'CI-Smarty Example'; $data['keyword'] = 'codeigniter,smarty,template'; // Such as traditional syntax $string = $this->template->parse( 'home/index', $data, true ); // default file ext is `.html` echo $string; }
in Controller
<?php function index() { $this->load->library( 'template' ); $CI =& get_instance(); $this->template->assign( 'CI', $CI ); $this->template->display( 'home/index', $assign ); // default file ext is `.html` }
in HTML
<!DOCTYPE HTML> <html> <head></head> <body> hello, world<br /> This site's name is {$CI->config->item( 'site_name' )}. </body>
{nocache}{/nocache}
in HTML
<!DOCTYPE HTML> <html> <head></head> <body> hello, world the time is {nocache}{$smarty.now|date_format}{/nocache} </body>