smarty if 操作符

來源:互聯網
上載者:User
Smarty 中的 if 語句和 php 中的 if 語句一樣靈活易用,並增加了幾個特性以適宜模板引擎. if 必須於 /if 成對出現. 可以使用 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、==、!=、>、<、<=、>=. 使用這些修飾詞時必須和變數或常量用空格格開. eq相等,ne、neq不相等,gt大於,lt小於,gte、ge大於等於,lte、le 小於等於,not非, mod求模。is [not] div by是否能被某數整除,is [not] even是否為偶數$a is [not] even by $b即($a / $b) % 2 == 0,is [not] odd是否為奇,$a is not odd by $b即($a / $b) % 2 != 0 樣本: equal/ not equal/ greater than/ less than/ less than or equal/ great than or equal/後面的就不用說了 Smarty 中的 if 語句和php中的 if 語句一樣靈活易用,並增加了幾個特性以適宜模板引擎. if 必須於 /if 成對出現. 可以使用 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、==、!=、>、<、<=、>=. 使用這些修飾詞時必須和變數或常量用空格格開. 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 qualifiersmust 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}   {if $_global_password} 是判斷變數存不存在.... {if $_global_password!==''} 是判斷變數等不等於空.... Smarty 中的 if 語句和 php 中的 if 語句一樣靈活易用,並增加了幾個特性以適宜模板引擎. if 必須於 /if 成對出現. 可以使用 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、==、!=、>、<、<=、>=. 使用這些修飾詞時必須和變數或常量用空格格開.  equal : 相等、not equal:不等於、greater than:大於、less than:小於、less than or equal:小於等於、great than or equal:大於等於、is even:是偶數、is odd:是奇數、is not even:不是偶數、is not odd:不是奇數、not:非、mod:取餘、div by:被。。。除  下面是一段除法的樣式:<{if $count is div by 4}></tr><tr><{/if}>

 

聯繫我們

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