PHP中Smarty模版怎么用

这篇文章主要为大家展示了“PHP中Smarty模版怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“PHP中Smarty模版怎么用”这篇文章吧。

具体如下:

Index.php:

require('../libs/Smarty.class.php');
$smarty = new Smarty;
// 添加自定义调节器
$smarty->registerPlugin("modifier", "e", "htmlspecialchars");
$smarty->registerPlugin("modifier", "trim", "trim");
//$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
//定义标识符
$smarty->left_delimiter = '{ ';
$smarty->right_delimiter = ' }';
//绑定变量
$smarty->assign("test_html", "<a>haha</a>");
$smarty->display('index.tpl');

index.tpl:

<h2>{ $test_html|e }</h2>

后记:如何让VS支持tpl扩展名的HTML编辑

在菜单[工具>选项]中设置,如下图:

PHP中Smarty模版怎么用

以上是“PHP中Smarty模版怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!