欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ECSHOP模板系統(tǒng)控制標(biāo)簽使用介紹

  發(fā)布時(shí)間:2015-09-29 10:42:23   作者:佚名   我要評(píng)論
這篇文章主要介紹了ECSHOP模板系統(tǒng)控制標(biāo)簽使用介紹,需要的朋友可以參考下

ECSHOP模板系統(tǒng)控制標(biāo)簽介紹說(shuō)明,本文將為您介紹ecshop中基本的控制函數(shù)標(biāo)簽的使用參數(shù)和方法,其中包括if標(biāo)簽、foreach標(biāo)簽、for標(biāo)簽等,其實(shí)Smarty 中的 if 語(yǔ)句和 php 中的 if 語(yǔ)句一樣靈活易用,并增加了幾個(gè)特性以適宜模板引擎, if必須于/if 成對(duì)出現(xiàn). 可以使用 else 和 elseif 子句。

if,elseif,else

描述:

Smarty 中的 if 語(yǔ)句和 php 中的 if 語(yǔ)句一樣靈活易用,并增加了幾個(gè)特性以適宜模板引擎. if必須于 /if 成對(duì)出現(xiàn). 可以使用 else 和 elseif 子句. 可以使用以下條件修飾詞:eq、ne、neq、gt、lt、lte、le、gte、ge、is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、==、!=、>、<、<=、>=. 使用這些修飾詞時(shí)必須和變量或常量用空格格開(kāi)。

例子:

{if $name eq "Fred"}
Welcome Sir.
{elseif $name eq "Wilma"}
Welcome Ma'am.
{else}
Welcome, whatever you are.
{/if}
{* an example with "or" logic *}
{if $name eq "Fred" or $name eq "Wilma"}
...
{/if}
{* same as above *}
{if $name == "Fred" || $name == "Wilma"}
...
{/if}
{* the following syntax will NOT work, conditional qualifiers
must be separated from surrounding elements by spaces *}
{if $name=="Fred" || $name=="Wilma"}
...
{/if}
{* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
...
{/if}
{* you can also embed php function calls *}
{if count($var) gt 0}
...
{/if}
{* test if values are even or odd *}
{if $var is even}
...
{/if}
{if $var is odd}
...
{/if}
{if $var is not odd}
...
{/if}
{* test if var is divisible by 4 *}
{if $var is div by 4}
...
{/if}
{* test if var is even, grouped by two. i.e.,
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
{if $var is even by 2}
...
{/if}
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
{if $var is even by 3}
...
{/if}

foreach,foreachelse

iteration:

iteration 用于顯示當(dāng)前循環(huán)的執(zhí)行次數(shù)[待考]
iteration 總是從 1 開(kāi)始,每執(zhí)行一次增加 1.[待考]

first:

當(dāng)前 foreach 循環(huán)第一次執(zhí)行時(shí) first 被設(shè)置成 true.

last:

當(dāng)前 foreach 循環(huán)執(zhí)行到最后一遍時(shí) last 被設(shè)置成 true.

show:

show 是 foreach 的一個(gè)參數(shù). 取值為布爾值 true 或 false. 如果指定為 false 該循環(huán)不顯示,如果循環(huán)指定了 foreachelse 子句,該子句顯示與否也取決于 show 的取值。

total:

total 用于顯示循環(huán)執(zhí)行的次數(shù),可以在循環(huán)中或循環(huán)執(zhí)行后調(diào)用。

屬性 類(lèi)型 是否必須 缺省值 描述
from string Yes n/a 待循環(huán)數(shù)組的名稱(chēng)
item string Yes n/a 當(dāng)前處理元素的變量名稱(chēng)
key string No n/a 當(dāng)前處理元素的鍵名
name string No n/a 該循環(huán)的名稱(chēng),用于訪問(wèn)該循環(huán)

描述:

foreach 是除 section 之外處理循環(huán)的另一種方案(根據(jù)不同需要選擇不同的方案)。

foreach 用于處理簡(jiǎn)單數(shù)組(數(shù)組中的元素的類(lèi)型一致),它的格式比 section 簡(jiǎn)單許多,缺點(diǎn)是只能處理簡(jiǎn)單數(shù)組。

foreach 必須和 /foreach 成對(duì)使用,且必須指定 from 和 item 屬性。
name 屬性可以任意指定(字母、數(shù)字和下劃線的組合)。
foreach 可以嵌套,但必須保證嵌套中的 foreach 名稱(chēng)唯一。
from 屬性(通常是數(shù)組)決定循環(huán)的次數(shù)。
foreachelse 語(yǔ)句在 from 變量沒(méi)有值的時(shí)候被執(zhí)行。

例子1:

{* 該例將輸出數(shù)組 $custid 中的所有元素的值 *}
{foreach from=$custid item=curr_id}
id: {$curr_id}<br>
{/foreach}

輸出:

id: 1000<br>
id: 1001<br>
id: 1002<br>

例子2:

{* The key contains the key for each looped value
assignment looks like this:
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
*}
{* 鍵就是數(shù)組的下標(biāo),請(qǐng)參看關(guān)于數(shù)組的解釋 *}
{foreach name=outer item=contact from=$contacts}
{foreach key=key item=item from=$contact}
{$key}: {$item}<br>
{/foreach}
{/foreach}

輸出:

phone: 1<br>
fax: 2<br>
cell: 3<br>
phone: 555-4444<br>
fax: 555-3333<br>
cell: 760-1234<br>

foreach 循環(huán)有自己的變量名,使用該變量名可以訪問(wèn)該循環(huán). 使用方法為{$smarty.foreach.foreachname.varname},其中 foreachname 即在 foreach 中指定的name 屬性。

相關(guān)文章

最新評(píng)論