[英]Smarty - include subpages to main page
I have default template file (main.tpl) and I want to include subpages between <body>
tags. 我有默认模板文件(main.tpl),并且我想在
<body>
标签之间包含子页面。
So when user clicks for expample on link News, it'll show news.php ($smarty->display("news.tpl");) combined with main.tpl 因此,当用户单击链接News上的示例时,它将显示结合main.tpl的news.php($ smarty-> display(“ news.tpl”);)
--> 1st part of main.tpl + news.tpl + 2nd part of main.tpl. -> main.tpl的第一部分+ news.tpl + main.tpl的第二部分。
News.tpl would contain some text and php code, nothing else. News.tpl会包含一些文字和PHP代码,没有别的。 Eg.
例如。
Hello, <php echo $username ?>. Some random text.
您应该只$smarty->display("main.tpl")
,并将news.tpl包含在main.tpl中。
If your templates contain PHP code, you don't need Smarty at all. 如果模板包含PHP代码,则根本不需要Smarty。 Just
include
your template file. 只需
include
您的模板文件。
In PHP assign template name to smarty variable: 在PHP中,将模板名称分配给smarty变量:
$smarty->assign('module', 'news');
$smarty->display('main.tpl');
In main.tpl just include module template: 在main.tpl中,仅包含模块模板:
<body>{include file="$module.tpl"}</body>
You can find more about {include}
smarty function here: http://www.smarty.net/docs/en/language.function.include.tpl 您可以在此处找到有关
{include}
smarty函数的更多信息: http : //www.smarty.net/docs/en/language.function.include.tpl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.