如何在smarty模板中执行php代码
来源:岁月联盟
时间:2012-05-02
如果你真正的需要在模板中使用脚本程序,smarty也提供了{php}标签,允许programmer在表现层混入php代码(再次提示:这种不利于逻辑层与表现层的分离,违背了程序与结构的分离)。看一看如何在模板中插入php代码:
phpCode.tpl:
1. {php}
2. echo "There is php code in the template of smarty";
3. for($i=1 ; $i<=3; $i++){
4. echo "but it's better to avoid php code in your case!";
5. }
6. {/php}
phpCode.php
1. <?
2. include("libs/smarty.class.php");
3. $smarty = new smarty();
4. $smarty->display("phpCode.tpl")
5. ?>
效果图:

摘自 沙漠的蜗牛80
上一篇:php小功能详解