smarty 模板怎样使用php标签

smarty模板貌似默认是屏蔽掉{php}{/php}标签的,要怎么才能在模板中使用{php}{/php}标签呢?怎么办?没人懂吗?... smarty模板貌似默认是屏蔽掉{php}{/php}标签的,要怎么才能在模板中使用{php}{/php}标签呢?怎么办?没人懂吗? 展开
 我来答
百度网友d7e10266d1
推荐于2017-11-25 · TA获得超过5480个赞
知道小有建树答主
回答量:713
采纳率:0%
帮助的人:698万
展开全部
smarty本身是不推荐使用php标记的,可以通过编写插件(block,function,modifier)来代替。
smarty默认不开启php标记,需要在创建smarty对象后做如下设置:
$smarty->php_handling = SMARTY_PHP_ALLOW ;
追问
不好意思,这才是模板文件,刚打错

asdasda

echo "dasjkhdkasjh";

还是不能输出php标签里echo的值
追答
需要在服务器端设置:
$smarty->php_handling = SMARTY_PHP_ALLOW ; 来开启{php}模板标签,默认此标签是不可用的
示例代码:
require("./Smarty/Config_File.class.php");
require(“./Smarty/Smarty.class.php");

//init smarty
$smarty=new Smarty();
$smarty->cache_dir =WEB_ROOT.APP_DIR."/".trim($cfg["cache_dir"])."/";
$smarty->template_dir =WEB_ROOT.APP_DIR."/".trim($cfg["template_dir"])."/";
$smarty->compile_dir =WEB_ROOT.APP_DIR."/".trim($cfg["compiler_dir"])."/";
$smarty->config_dir =WEB_ROOT.APP_DIR."/".trim($cfg["config_dir"])."/";
$smarty->left_delimiter =trim($cfg["left_delimiter"]);
$smarty->right_delimiter =trim($cfg["right_delimiter"]);
$smarty->caching =false;
$smarty->php_handling = SMARTY_PHP_ALLOW ;
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
1101947275
2012-12-13
知道答主
回答量:7
采纳率:0%
帮助的人:5.9万
展开全部
用.tpl模版文件 显示你所说的echo的值,只是不能像你在写php中那样写, 要用模版标签<{......}>显示。
事例代码:
php文件中写的是:
<tr class="tableline">
<td width="24%" class="tdline"><b>留言者:</b><? echo $row['sender'];?></td>
<td width="39%" class="tdline"><b>IP地址:</b><? echo $row['sendIP'];?></td>
<td width="37%" class="tdline"><b>日期:</b><? echo $row['sendDateTime'];?></td>
</tr>
模版文件中就变了:
<tr>
<td width="24%" class="tdline"><b>留言者:</b><{$msg.sender}></td>
<td width="39%" class="tdline"><b>IP地址:</b><{$msg.sendIP}></td>
<td width="37%" class="tdline"><b>日期:</b><{$msg.sendDateTime}></td>
</tr>
如果对你有帮助,请选为最佳答案哦。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式