Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

{if},{elseif},{else}

Smarty鐨{if}鏉′欢鍒ゆ柇鍜孭HP鐨if 闈炲父鐩镐技锛屽彧鏄鍔犱簡涓浜涚壒鎬с 姣忎釜{if}蹇呴』鏈変竴涓厤瀵圭殑{/if}. 涔熷彲浠ヤ娇鐢{else}{elseif}. 鍏ㄩ儴鐨凱HP鏉′欢琛ㄨ揪寮忓拰鍑芥暟閮藉彲浠ュ湪if鍐呬娇鐢紝濡||, or, &&, and, is_array(), 绛夌瓑.

濡傛灉寮鍚簡瀹夊叏鏈哄埗锛岄偅涔堝彧鏈夊湪$php_functions璁剧疆鍏佽鐨凱HP鍑芥暟鎵嶈兘浣跨敤銆 鍙傝瀹夊叏鏈哄埗

涓嬮潰鏄彲鐢ㄧ殑杩愮畻绗﹀垪琛紝浣跨敤涓兘浼氭斁鍒板厓绱犵殑涓棿骞朵笖鐢ㄧ┖鏍煎垎闅斻 娉ㄦ剰鍒楄〃涓璠鏂规嫭鍙穄鐨勬槸鍙夌殑锛岃屼笖杩樹細鍒楀嚭瀵瑰簲PHP鐨勮〃杈惧紡銆

杩愮畻绗 鍒悕 璇硶绀轰緥 鍚箟 瀵瑰簲PHP璇硶
== eq $a eq $b 绛変簬 ==
!= ne, neq $a neq $b 涓嶇瓑浜 !=
> gt $a gt $b 澶т簬 >
< lt $a lt $b 灏忎簬 <
>= gte, ge $a ge $b 澶т簬绛変簬 >=
<= lte, le $a le $b 灏忎簬绛変簬 <=
=== $a === 0 缁濆绛変簬 ===
! not not $a 闈 (涓鍏冭繍绠) !
% mod $a mod $b 鍙栨ā %
is [not] div by $a is not div by 4 鍙栨ā涓0 $a % $b == 0
is [not] even $a is not even [闈瀅 鍙栨ā涓0 (涓鍏冭繍绠) $a % 2 == 0
is [not] even by $a is not even by $b 姘村钩鍒嗙粍 [闈瀅 骞冲潎 ($a / $b) % 2 == 0
is [not] odd $a is not odd [闈瀅 濂囨暟 (涓鍏冭繍绠) $a % 2 != 0
is [not] odd by $a is not odd by $b [闈瀅 濂囨暟鍒嗙粍 ($a / $b) % 2 != 0

Example聽7.44.聽{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}


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

{* check for array. *}
{if is_array($foo) }
   .....
{/if}

{* check for not null. *}
{if isset($foo) }
   .....
{/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}

  

Example聽7.45.聽{if} 鐨勬洿澶氫緥瀛

 
{if isset($name) && $name == 'Blog'}
     {* do something *}
{elseif $name == $foo}
    {* do something *}
{/if}

{if is_array($foo) && count($foo) > 0}
    {* do a foreach loop *}
{/if}
  

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 14 plus 20? (Are you human?)

Advertisement