php—Smarty-4 (21),phpsmarty-421_PHP教程

來源:互聯網
上載者:User

php—Smarty-4 (21),phpsmarty-421


Smarty函數---外掛程式

1) 內建函數 sysplugins 不允許修改

2) 自訂函數 plugins 可以修改

1、capture 捕獲一段內容,但不輸出

文法:

{capture name=‘var’}

內容

{/capture}

Name:將內容儲存到指定的變數中

{$smarty.capture.var}

在模板中,需要反覆輸出的大量內容,可以考慮使用capture捕獲。

2、config_load 載入設定檔

{config_load file=“file”section=“section”}

file:設定檔名稱

section:引用哪個配置節 選擇性參數

引用文法:

{#var#}

{$smarty.config.var}

3、foreach,foreachelse 用於遍曆數組

文法:

{foreach from=數組 key=鍵 name=名稱 item=內容 }

{foreachelse} 當要遍曆的數組沒有任何元素時,執行foreachelse後面的語句

{/foreach}

From:要遍曆的數組

Item:遍曆到的索引值

Key:遍曆到的鍵名

Name:為foreach語句命名

Foreach內建變數

$smarty.foreach.name.index :索引 從0開始

$smarty.foreach.name.iteration :索引 從1開始

$smarty.foreach.name.first :當第一次執行迴圈時,該值為true

$smarty.foreach.name.last :當最後一次執行迴圈時,該值為true

$smarty.foreach.name.total :迴圈總數

4、include 引用另一個模板檔案

{include file=“file” assign=“var” [var ...]}

File:要引入的模板檔案

Assign:將結果儲存,但本次不輸出

[var …] :選擇性參數,為模板檔案傳參

5、include_php 包含一個php檔案

{ include_php file=“file” assign=“var” once=“true|false”}

File:要引入的php檔案

Assign:儲存輸出結果,但本次不輸出

Once:是否只包含一次 true:是 false:否

這個函數在smarty2.6中是可用的,但在3.0中將這個函數移除,如果還想使用這個函數,可以引用SmartyBC.class.php這個類檔案

6、insert 在模板中,執行一個php函數

文法:

{ insert name=“func” [var ...] }

Name :被調用的php函數名

[var ...] :調用函數時指定參數 選擇性參數

Insert和include_php是同樣的。都是2.6中的函數,在3.0中,將這個功能放到SmartyBC.class.php這個檔案中了。

注意:inser引用的php函數的名稱必須以insert_為首碼

7、if elseif else

{if}

{elseif}

{else}

{/if}

8、ldelim 、rdelim 模板中的 { } 的轉義符

{ldelim}

{rdelim}

9、literal literal標記中間的內容不會被smarty所解析

{literal}

……

{/literal}

10、php 可以在一對php標記中寫php代碼

{php}

……

{/php}

http://www.bkjia.com/PHPjc/993264.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/993264.htmlTechArticlephp—Smarty-4 (21),phpsmarty-421 Smarty函數---外掛程式 1) 內建函數 sysplugins 不允許修改 2) 自訂函數 plugins 可以修改 1、capture 捕獲一段內容,...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.