Php Smarty模板化继承-传递变量?

Php Smarty模板化继承-传递变量?,php,smarty,templating,Php,Smarty,Templating,好的,开始吧,我使用的是最新的Smarty版本,一切都设置好了 我的问题是,我有一个整个网站的主模板名为layout.tpl,然后每个页面的子模板home.tpl,about.tpl等 index.php(用于主页) Home.tpl {extends file="layout.tpl"} {block name=title}Home{/block} {block name=body} <div>Sample</div> {/block} 我的问题是layout.tpl

好的,开始吧,我使用的是最新的Smarty版本,一切都设置好了

我的问题是,我有一个整个网站的主模板名为layout.tpl,然后每个页面的子模板home.tpl,about.tpl等

index.php(用于主页)

Home.tpl

{extends file="layout.tpl"}
{block name=title}Home{/block}
{block name=body}
<div>Sample</div>
{/block}
我的问题是layout.tpl中的html内容是隐藏的还是显示的,这取决于用户是管理员还是普通用户。如何将这些PHP值传递到layout.tpl?通过home.tpl?有没有更好的方法来实现这一点


谢谢

我没有使用Smarty v3和继承,只是继续上面的示例代码,但是
assign()
怎么样?我知道当您有一个包含另一个文件的模板文件时,所有分配的变量仍然有效,并且能够在
{include}
语句中分配新的变量

index.php(用于主页)

Home.tpl(未更改)

第三方物流

// Long html file which makes use of the blocks from home, about ect...
<html>
    ...
    <h1>{$some_header}</h1>
    // Long html file which makes use of the blocks from home, about ect...
</html>

...
{$some_header}
//长html文件,它利用了从家里来的块,关于等。。。
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->assign('some_header', 'hello!');

$smarty->display('home.tpl');
<html>
    ...
    <h1>{$some_header}</h1>
    // Long html file which makes use of the blocks from home, about ect...
</html>