2
好吧,从头开始我正在使用最新的Smarty版本,并且设置了所有内容。Smarty模板继承 - 传递变量?
我的问题是,我有叫layout.tpl整个网站的主模板,然后为每个页面的子模板home.tpl,about.tpl等...
的index.php(家庭)
require('Smarty.class.php');
// --
$smarty = new Smarty;
$smarty->template_dir = 'C:/xampp/htdocs/EMP3/view/templates';
$smarty->config_dir = 'C:/xampp/htdocs/EMP3/view/config';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';
$smarty->display('home.tpl');
Home.tpl
{extends file="layout.tpl"}
{block name=title}Home{/block}
{block name=body}
<div>Sample</div>
{/block}
Layout.tpl
// Long html file which makes use of the blocks from home, about ect...
我的问题是,layout.tpl中的html内容是隐藏的或显示取决于用户是管理员还是普通用户。我如何将这些PHP值传递给layout.tpl?通过home.tpl?有没有更好的方法来实现这一目标?
感谢