Smarty {if},{elseif},{else} --Built-in Functions
来源:互联网 发布:淘宝内部优惠券在哪领 编辑:程序博客网 时间:2024/06/06 13:55
If The following is a list of recognized qualifiers, which must be separated from surrounding elements by spaces. Note that items listed in [brackets] are optional. PHP equivalents are shown where applicable. Example 7.15. {if} statements Example 7.16. {if} with more examples{if},{elseif},{else}
{if}
statements in Smarty have much the same flexibility as PHP if statements, with a few added features for the template engine. Every {if}
must be paired with a matching {/if}
. {else}
and {elseif}
are also permitted. All PHP conditionals and functions are recognized, such as ||, or, &&, and, is_array(), etc.$security
is enabled, only PHP functions from the IF_FUNCS array from$security_settings
are allowed.Qualifier Alternates Syntax Example Meaning PHP Equivalent ==eq$a eq $bequals==!=ne, neq$a neq $bnot equals!=>gt$a gt $bgreater than><lt$a lt $bless than<>=gte, ge$a ge $bgreater than or equal>=<=lte, le$a le $bless than or equal<==== $a === 0check for identity===!notnot $anegation (unary)!%mod$a mod $bmodulous%is [not] div by $a is not div by 4divisible by$a % $b == 0is [not] even $a is not even[not] an even number (unary)$a % 2 == 0is [not] even by $a is not even by $bgrouping level [not] even($a / $b) % 2 == 0is [not] odd $a is not odd[not] an odd number (unary)$a % 2 != 0is [not] odd by $a is not odd by $b[not] an odd grouping($a / $b) % 2 != 0{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}
{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}
来源:http://www.smarty.net/docsv2/en/language.function.if.tpl
- Smarty {if},{elseif},{else} --Built-in Functions
- smarty if,elseif,else 新语法
- smarty模板引擎之if, elseif else
- Smarty-内建函数(if,elseif,else)
- smarty模板引擎之if, elseif else
- if elseif elseif elseif else...
- php $smarty 模板的控制结构 if-elseif-else
- if-elseif-else语句
- if...elseif...else 的运用
- if elseif else 判断语句
- shell 脚本 if elseif else
- 42. PHP elseif/else if
- elseif和else if区别
- shell 脚本 if elseif else
- C# 选择结构 if、if..else、if..elseif...else、switch
- Built-in Functions
- Python Built-in Functions
- awk built-in functions
- 直线提取源码
- .net返回上一页并刷新
- ArrayList和Vector,HashMap和HashTable的区别
- [转]Python-memcached的基本使用
- #asp.net应用程序目录 虚拟主机的配置
- Smarty {if},{elseif},{else} --Built-in Functions
- WPF中动态更新TextBlock文字中的超链接
- vs2003DataGrid控件点击单元格选择行
- 在文章中主标题和副标题的格式问题
- Adobe Acrobat 关于双击扩展的问题
- 如何在ubuntu 上安装tomcat::how to install tomcat on Ubuntu
- 键盘keyCode代码
- BizTalk Server 2010 - 业务活动监视(BAM) [ 下篇 ]
- Nginx源代码分析--基本数据结构--hash