display() テンプレートを表示します。 説明 voiddisplay stringtemplate stringcache_id stringcompile_id テンプレートを表示します (fetch() と違い出力を行います)。 第1パラメータには、有効な テンプレートリソース の種類を含むパスを指定する事ができます。任意の第2パラメータには キャッシュID を渡す事ができます。 詳細は キャッシュの項 を参照してください。 ¶meter.compileid; display() 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('data', $db_data); } // 出力を表示します $smarty->display('index.tpl'); ?> ]]> display() 関数にテンプレートリソースを指定した例 $template_dir ディレクトリ外のファイルを表示するためには、 テンプレートリソース を指定します。 display('/usr/local/include/templates/header.tpl'); // ファイルの絶対パス (上と同じ) $smarty->display('file:/usr/local/include/templates/header.tpl'); // windows環境の絶対パス (接頭辞に"file:"を使う必要があります) $smarty->display('file:C:/www/pub/templates/header.tpl'); // "db"と名付けられたテンプレートリソースからインクルードします $smarty->display('db:header.tpl'); ?> ]]> fetch() および template_exists() も参照してください。