smarty @Wiki

display()

最終更新:

匿名ユーザー

- view
だれでも歓迎! 編集

display()


void display ( string template [, string cache_id [, string compile_id]])

テンプレートを表示します。
第1パラメータには、有効なテンプレートリソースの種類を含んだパスを指定する事ができます。
任意の第2パラメータにはキャッシュIDを渡す事ができます。詳細は、キャッシュの項を参照して下さい。

任意の第3パラメータとしてcompile_idを渡す事が出来ます。
異なる言語でコンパイルされた別々のテンプレートが存在するような、同じテンプレートの異なるバージョンをコンパイルしたい場合に利用します。他にも、1つ以上の$template_dirを持っているが$compile_dirが1つしかない場合です。
それぞれの$template_dirのために別々のcompile_idをセットしなければ、同名のテンプレートはお互いに上書きされてしまいます。
この関数をコールする度にcompile_idをセットする代わりに、一度$compile_id変数をセットする事が出来ます。

例 1. display

<?php
include("Smarty.class.php");
$smarty = new Smarty;
$smarty->caching = true;

if(!$smarty->is_cached("index.tpl")) {

 // ダミーデータ
 $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);

}
$smarty->display("index.tpl");
?>

$template_dirディレクトリ外のファイルを表示するためには、テンプレートリソースを指定します。

例 2. display関数にテンプレートリソースを指定した例

<?php
$smarty->display("/usr/local/include/templates/header.tpl");

$smarty->display("file:/usr/local/include/templates/header.tpl");

$smarty->display("file:C:/www/pub/templates/header.tpl");

$smarty->display("db:header.tpl");
?>

テンプレートをメモリに読込むにはfetch?を使用。
ウィキ募集バナー