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

createTemplate() — テンプレートオブジェクトを返す

説明

string createTemplate(string template,
                      object parent);

string createTemplate(string template,
                      array data);

string createTemplate(string template,
                      string cache_id,
                      string compile_id,
                      object parent);

string createTemplate(string template,
                      string cache_id,
                      string compile_id,
                      array data);

この関数は、テンプレートオブジェクトを作成します。このテンプレートを、 display あるいは fetch メソッドでレンダリングすることができます。 次のパラメータを使います。

  • template は、有効な テンプレートリソース 型およびパスでなければなりません。

  • cache_id はオプションのパラメータです。 この関数をコールするたびにこのパラメータを指定するかわりに、変数 $cache_id を使うこともできます。 これは、同じテンプレートを使う異なるコンテンツ (異なる製品を表示するページなど) をキャッシュする場合に使います。 詳細は キャッシュ を参照ください。

  • compile_id はオプションのパラメータです。 この関数をコールするたびにこのパラメータを指定するかわりに、変数 $compile_id を使うこともできます。 これは、同じテンプレートの異なるバージョンをコンパイルしたい場合 (言語ごとに別々にコンパイルしたい場合など) に使います。

  • parent はオプションのパラメータです。 これは、メイン Smarty オブジェクトやユーザが作成したデータオブジェクト、 あるいはユーザが作成したテンプレートオブジェクトなどへのアップリンクです。 これらのオブジェクトは連結することができます。 テンプレートからは、連結したオブジェクト内で代入されたすべての値にアクセスできます。

  • data はオプションのパラメータです。 これは、オブジェクトに代入された変数の 名前/値 のペアを含む連想配列です。

Example 13.15. createTemplate()


<?php
include('Smarty.class.php');
$smarty = new Smarty;

// テンプレートオブジェクトとそのスコープを作成します
$tpl = $smarty->createTemplate('index.tpl');

// 変数をテンプレートのスコープに代入します
$tpl->assign('foo','bar');

// テンプレートを表示します
$tpl->display();
?>

    


display(), および templateExists() も参照ください。