鍍金池/ 教程/ PHP/ Smarty if,elseif,else
Smarty安裝
Smarty insert
Smarty 建立緩存
Smarty調(diào)試控制臺
Smarty if,elseif,else
Smarty include_php
Smarty多個(gè)緩存
Smarty方法
Smarty section,sectionelse
Smarty注釋代碼
Smarty屬性
Smarty緩沖處理函數(shù)
Smarty變量調(diào)節(jié)器
Smarty函數(shù)
Smarty組合修改器
Smarty雙引號里值的嵌入
Smarty預(yù)過濾器
Smarty foreach,foreachelse
Smarty include
Smarty Caching緩存
Smarty變量
Smarty assign用法
Smarty控制插件輸出緩沖
Smarty從配置文件讀取的變量
Smarty對象
Smarty literal
Smarty緩存集合
Smarty教程
Smarty display方法
Smarty自定義函數(shù)
Smarty配置文件
Smarty擴(kuò)展設(shè)置
Smarty數(shù)學(xué)運(yùn)算
Smarty輸出濾鏡
Smarty fetch方法

Smarty if,elseif,else

if,elseif,else

Smarty 中的 if 語句和 php 中的 if 語句一樣靈活易用,并增加了幾個(gè)特性以適宜模板引擎. if 必須于 /if 成對出現(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í)必須和變量或常量用空格格開.


Example 7-11. if statements
例 7-11. if 語句演示

{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}


上一篇:Smarty多個(gè)緩存下一篇:Smarty屬性