欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

smarty include file 使用变量的方法_PHP教程

程序员文章站 2023-12-25 14:42:15
...
今天在用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}

您可能感兴趣的文章

  • smarty模板中使用php函数以及smarty模板中如何对一个变量使用多个函数
  • smarty模板保留变量总结
  • smarty变量操作符总结
  • Firefox 提示event is not defined错误的解决办法
  • PHP报Fatal error Allowed memory size of...内存不足的错误应该如何解决
  • Smarty模板变量操作符总结
  • select into from 提示 Undeclared variable.....错误的解决办法
  • Thinkphp 模板中常用的系统变量总结

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/764077.htmlTechArticle今天在用smarty做个网站的时候,由于有这么一个需要 include file="动态路径" ,这就需要在file的值里面使用变量了,尝试了半天终于解决,自...

上一篇:

下一篇: