[PHP-users 20799]Re: smartyテンプレートをメモリーから読み込む 出力をメモリーに読み込む

Takafumi Suzuki taka @ kpnet.co.jp
2004年 3月 15日 (月) 11:16:08 JST


こんにちは。鈴木と申します。

> 【テンプレートをメモリーから読み込む】
Smarty自体あまり触ったことがないので
他に良い方法があるのかも知れませんが
自分も以前同じような事をしたくて
http://sunset.freespace.jp/smarty/SmartyManual_2-6-2J_html/templates.from.elsewhere.html
を参考に以下のようにしました。

------- ここから ---------------------------------

function get_template($tpl_name,&$tpl_source,&$smarty_obj){
 $tpl_source = $tpl_name;
 return true;
}

function get_timestamp($tpl_name,&$tpl_timestamp,&$smarty_obj){
 $tpl_timestamp = time();
 return true;
}

function get_secure($tpl_name,&$smarty_obj){
 return true;
}

function get_trusted($tpl_name,&$smarty_obj){

}

$smarty = new MySmarty();
$smarty->register_resource("hensu",array("get_template",
           "get_timestamp",
           "get_secure",
           "get_trusted"));

$tmpl = "テンプレートの文字列";
------- ここまで ---------------------------------

としておき、
$result = $smarty->fetch("hensu:".$tmpl);
として希望通りの動きをしました。

------------------------------
Takafumi Suzuki
(taka @ kpnet.co.jp)



PHP-users メーリングリストの案内