smarty include file 使用變數的方法_PHP教程

來源:互聯網
上載者:User
今天在用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 模板中常用的系統變數總結

http://www.bkjia.com/PHPjc/764077.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/764077.htmlTechArticle今天在用smarty做個網站的時候,由於有這麼一個需要 include file="動態路徑" ,這就需要在file的值裡面使用變數了,嘗試了半天終於解決,自...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.