Heim  >  Artikel  >  Backend-Entwicklung  >  smarty include file 使用变量的方法_PHP教程

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

WBOY
WBOYOriginal
2016-07-13 10:31:251008Durchsuche

今天在用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的值里面使用变量了,尝试了半天终于解决,自...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn