php—Smarty-5 (22),phpsmarty-522_PHP教程

來源:互聯網
上載者:User

php—Smarty-5 (22),phpsmarty-522


接上一篇

11、section,sectionelse section是一種迴圈結構語句,主要用於遍曆數組

文法:

{section name=名稱 loop=迴圈數組(次數) start=開始(0) step=步階(1) max=最大迴圈次數}
{sectionelse}

{/section}

Name:為section語句命名 必選

Loop:迴圈數組 必選

Start:開始索引 預設值:0

Step:步長 預設值:1

Max:最大迴圈次數 預設值:總長度

Foreach和section的區別:

Foreach是指直接對一個數組進行遍曆

Section是一種迴圈語句,它的迴圈次數由數組個數決定

Section在遍曆數組是有更多的選擇性

l section的內建變數

{$smarty.section.name.index} 迴圈索引

{$smarty.section.name.index_prev} 上一次迴圈索引

{$smarty.section.name.index_next} 下一次迴圈索引

{$smarty.section.name.iteration } 迴圈索引 從1開始

{$smarty.section.name.first|last} 第1次和最後一次執行時這兩個值為true

{$smarty.section.name.total} 迴圈總次數

12、strip 去除前後連續空格

文法:

{strip}

……

{/strip}

二、自訂函數

1、assign 建立模板變數

{assign var=“var” value=“value”}

Var :指定變數名稱

Value:指定變的值

2、counter 計數器

文法:

{counter start=0 skip=2 print=false}

Start:開始的值

Skip:步長 預設為1

Print:本次是否輸出

3、cycle 實現輪轉

Values:要輪轉的值的列表

4、debug 開啟調試視窗

5、eval 計算變數的值

文法:

{eval var=#ErrorState# assign="state_error"}

Var:要計算的變數名

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

6、fetch 讀取檔案內容並輸出

{fetch file=“file” assign=“var”}

File:檔案名稱

Assign:儲存結果本次不輸出

7、html_image 在頁面中,列印一張圖片

{html_image file="pumpkin.jpg"}

File:圖片地址

8、html_table 將數組元素顯示到表格中 (只適用於簡單數組)

{html_table loop=$data cols=4 table_attr='border="0"'}

Loop:要遍曆的數組 必添

Cols:每行顯示多少個格 預設是三個

Table_atr:表格屬性

9、html_checkboxes 列印一組複選框

{html_checkboxes values=$cust_ids checked=$customer_id output=$cust_names separator="
"}

Values:值的數組

Checked:被選中項的值的數組

Output:文本的數組

Separator:分隔字元 每個複選項之間的分隔

Name:為這組複選框命名 注意:smarty會自動加上 [] ,表示是數組

模板代碼:

Php代碼:

http://www.bkjia.com/PHPjc/993262.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/993262.htmlTechArticlephp—Smarty-5 (22),phpsmarty-522 接上一篇 11、section,sectionelse section是一種迴圈結構語句,主要用於遍曆數組 文法: {section name=名稱 loop=迴圈...

  • 聯繫我們

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