私は、スムーズに保守可能な方法でテンプレート化のいくつかの段階を噛み合わせようとしています。インスタンス化された smarty オブジェクトを持ち、別の smarty オブジェクトをインスタンス化する別の php ページを含む外部ページがあります。私の質問は、外部インスタンスに変数を割り当て、内部インスタンスでアクセスできるようにする方法があるかどうかです。
概略的には、page.php を呼び出しています。
<?php
$tpl = new Smarty();
$tpl->assign("a","Richard");
$tpl->register_function('load_include', 'channel_load_include');
$tpl->display("outer_template.tpl");
function channel_load_include($params, &$smarty) {
include(APP_DIR . $params["page"]);
}
?>
outer_template.tpl:
<div> {load_include page="/otherpage.php"} </div>
otherpage.php:
<?php
$tpl2=new Smarty();
$tpl2->assign("b","I");
$tpl2->display("inner_template.tpl");
?>
inner_template.tpl:
<span id="pretentiousReference"> "Richard loves {$a}, that is I am {$b}" </span>
そして、私が見ているのは、「リチャードが愛している、つまり私は私だ」ということです。
内側のインスタンスから外側のインスタンスの変数にアクセスする方法はありますか、それともダンプしてタグ$_SESSION
でプルするだけですか? {php}
明らかに、私のアプリケーションはもう少し複雑ですが、これは私が核心の問題であると信じているものを明らかにしています。