display
顯示
void display (string template [, string cache_id [, string compile_id]])
顯示範本,需要指定一個合法的範本資源的類型和路徑。你還可以通過 第二個可選參數指定一個緩存號,相關的資訊可以查看緩存。
通過第三個可選參數,可以指定一個編譯號。這在你想把一個範本編譯成不同版本時使用,比如針對不同的語言編譯範本。編譯號的另外一個作用是,如果你 有多個$template_dir範本目錄,但只有一個$compile_dir編譯後存檔目錄,這時可以為每一個$template_dir範本目錄指 定一個編譯號,以避免相同的範本檔在編譯後會互相覆蓋。相對於在每一次調用display()的時候都指定編譯號,也可以通過設置$compile_id編譯號屬性來一次性設定。
Example 13-12. display
例子 13-12. 顯示
include("Smarty.class.php");
$smarty = new Smarty;
$smarty->caching = true;
// only do db calls if cache doesn't exist
// 只有在緩存不存在時才調用資料庫
if(!$smarty->is_cached("index.tpl"))
{
// dummy up some data
$address = "245 N 50th";
$db_data = array(
"City" => "Lincoln",
"State" => "Nebraska",
"Zip" = > "68502"
);
$smarty->assign("Name","Fred");
$smarty->assign("Address",$address);
$smarty->assign($db_data);
}
// display the output
// 顯示輸出
$smarty->display("index.tpl");
|
|
Use the syntax for template resources to display files outside of the $template_dir directory.
通過範本資源的語法來使用不在$template_dir範本目錄 下的檔。
Example 13-13. function display template resource examples
例子 13-13. 顯示範本資源
// absolute filepath
// 絕對路徑 by www.xuhuhu.com
$smarty->display("/usr/local/include/templates/header.tpl");
// absolute filepath (same thing)
// 絕對路徑(另外一種方式)
$smarty->display("file:/usr/local/include/templates/header.tpl");
// windows absolute filepath (MUST use "file:" prefix)
// WINDOS平臺下的絕對路徑(必須使用“file:”首碼)
$smarty->display("file:C:/www/pub/templates/header.tpl");
// include from template resource named "db"
// 從範本資源“db“中調用
$smarty->display("db:header.tpl");
|
|