smarty include file 使用变量的方法

 
更多

今天在用smarty做个网站的时候,由于有这么一个需要 include file=”动态路径” ,这就需要在file的值里面使用变量了,尝试了半天终于解决,自己觉得方法还是比较巧妙的,以前用smarty的时候就没有这么用过,特此记录一下。

下面就说说如何在include file的值中使用变量的方法吧!

include file={$path}”header.dwt” 或者 include file=”{$path}header.dwt”

以上这两种写法是错误的,在模板中直接使用变量行不通,我们可以在php文件中来写。最终正确写法如下:

在php文件中可以这么写:

$header=$path.'header.dwt';
$smarty->assign('header',$header);

在模板文件中则这样写:

{include file=$header}
打赏

本文固定链接: https://www.cxy163.net/archives/3980 | 绝缘体

该日志由 绝缘体.. 于 2013年06月28日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: smarty include file 使用变量的方法 | 绝缘体
关键字: , , , ,

smarty include file 使用变量的方法:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter