【问题标题】:how to display a variable that contain html template in smarty?如何在 smarty 中显示包含 html 模板的变量?
【发布时间】:2014-11-22 13:35:25
【问题描述】:
smarty中如何显示包含html模板的变量?
$smarty = new my_smarty();
$page_content = "<p>{$my_content}</p>";
$smary->assign("my_content","whatever...");
$smarty->display($page_content); // how to render $page_content ???
【问题讨论】:
标签:
variables
smarty
template-engine
【解决方案1】:
来自documentation:
Smarty 可以使用 string: 或 eval: 资源从字符串呈现模板。
string: 资源的行为与模板文件非常相似。模板源由字符串编译而成,并存储编译后的模板代码以供以后重用。 [...]
每次呈现页面时,eval: 资源都会评估模板源。 [...]
对于您的情况:
$smarty = new my_smarty();
$page_content = "<p>{$my_content}</p>";
$smary->assign("my_content","whatever...");
$smarty->display("string:" . $page_content);