ECSHOP模版系統(tǒng)中顯示標(biāo)簽主要是轉(zhuǎn)換HTML代碼,該特性使得在表格中交替輸出顏色或輪轉(zhuǎn)使用數(shù)組中的值變得很容易,或者是根據(jù)給定的數(shù)據(jù)創(chuàng)建選項(xiàng)組,創(chuàng)建日期下拉菜單,它可以顯示任意年月日。亦或者是根據(jù)給定的數(shù)據(jù)創(chuàng)建單選按鈕組等,本文就給大家講解一下ECSHOP模版系統(tǒng)的顯示標(biāo)簽。
cycle
屬性 | 類(lèi)型 | 是否必須 | 缺省值 | 描述 |
name | string | No | default | 輪轉(zhuǎn)的名稱(chēng) |
values | mixed | N/A | 待輪轉(zhuǎn)的值,可以是用逗號(hào)分隔的列表(請(qǐng)查看 delimiter 屬性)或一個(gè)包含多值的數(shù)組. | |
boolean | No | true | 是否輸出值 | |
advance | boolean | No | true | 是否使用下一個(gè)值(為 false 時(shí)使用當(dāng)前值) |
delimiter | string | No | , | 指出values 屬性中使用的分隔符,默認(rèn)是逗號(hào). |
assign | string | No | N/A | 輸出值將被賦給模板變量的名稱(chēng) |
描述:
Cycle 用于輪轉(zhuǎn)使用一組值. 該特性使得在表格中交替輸出顏色或輪轉(zhuǎn)使用數(shù)組中的值變得很容易。
如果需要在模板中使用多個(gè)輪轉(zhuǎn),需要給出唯一的 name 屬性.
用戶(hù)可以設(shè)置 print 屬性為 false 強(qiáng)制不輸出當(dāng)前值. 該特性可以很方便地略過(guò)某個(gè)值.
advance 屬性用于重復(fù)使用某個(gè)值. 當(dāng)該屬性設(shè)置為 false 時(shí),下次調(diào)用該輪轉(zhuǎn)時(shí)將輸出同樣的值.
如果指定了 “assign” 這個(gè)特殊屬性,該輪轉(zhuǎn)的輸出值將被賦給由 assign 指定的模板變量,而不是直接輸出。
例子:
{section name=rows loop=$data}<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}"><td>{$data[rows]}</td></tr>{/section}
輸出:
<tr bgcolor="#eeeeee"><td>1</td></tr><tr bgcolor="#d0d0d0"><td>2</td></tr><tr bgcolor="#eeeeee"><td>3</td></tr>
html_options
屬性 | 類(lèi)型 | 是否必須 | 缺省值 | 描述 |
values | array | Yes, unless using options attribute | N/A | 包含下拉列表各元素值的數(shù)組 |
output | array | Yes, unless using options attribute | N/A | 包含下拉列表各元素顯示值的數(shù)組 |
selected | string/array | No | empty | 已選定的元素或元素?cái)?shù)組 |
options | associative array | Yes, unless using values and output | N/A | 包含值和顯示的關(guān)聯(lián)數(shù)組 |
name | string | No | empty | 下拉菜單的名稱(chēng) |
描述:
自定義函數(shù) html_options 根據(jù)給定的數(shù)據(jù)創(chuàng)建選項(xiàng)組. 該函數(shù)可以指定哪些元素被選定. 要么必須指定 values 和 ouput 屬性,要么指定 options 替代。
如果給定值是數(shù)組,將作為 OPTGROUP 處理,且支持遞歸. 所有的輸出與 XHTML 兼容。
如果指定了可選屬性 name,該選項(xiàng)列表將將被置于<select name=”groupname”></select>標(biāo)簽對(duì)中. 如果沒(méi)有指定,那么只產(chǎn)生選項(xiàng)列表。
上表未提到的其它參數(shù)在 <select> 標(biāo)簽中以”名稱(chēng)/屬性”對(duì)的方式顯示. 如果沒(méi)有指定可選屬性 name 這些參數(shù)將被忽略。
例子:
index.php:
require('Smarty.class.php');$smarty = new Smarty;$smarty->assign('cust_ids', array(1000,1001,1002,1003));$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','JaneJohnson','Carlie Brown'));$smarty->assign('customer_id', 1001);$smarty->display('index.tpl');index.tpl:<select name=customer_id>{html_options values=$cust_ids selected=$customer_id output=$cust_names}</select>