Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

Name

display() — テンプレートを表示します。

説明

void display(string template,
             string cache_id,
             string compile_id);

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

任意の第3パラメータとして $compile_id を渡すことができます。 異なる言語でコンパイルされた別々のテンプレートが存在するような、 同じテンプレートの異なるバージョンをコンパイルしたい場合に利用します。 この関数をコールする度に compile_id を渡す代わりに、一度 $compile_id 変数をセットすることもできます。

Example 13.16. display()


<?php
include(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty();
$smarty->setCaching(true);

// キャッシュが存在しない場合はデータベースを呼び出します
if(!$smarty->isCached('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');
?>

   

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

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


<?php
// ファイルの絶対パス
$smarty->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() および templateExists() も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors