smarty 内置函数if 等判断
{if},{elseif},{else}
Smarty的{if}
条件判断和PHP的if 非常相似,只是增加了一些特性。 每个{if}
必须有一个配对的{/if}
. 也可以使用{else}
和 {elseif}
. 全部的PHP条件表达式和函数都可以在if内使用,如||, or, &&, and, is_array(), 等等.
如果开启了安全机制,那么只有在$php_functions
设置允许的PHP函数才能使用。 参见安全机制。
下面是可用的运算符列表,使用中都会放到元素的中间并且用空格分隔。 注意列表中[方括号]的是可选的,而且还会列出对应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}
参考:http://www.smarty.net/docs/zh_CN/language.function.if.tpl
smarty 内置函数if 等判断的更多相关文章
- Smarty内置函数之capture
capture的作用是: 捕获模板输出的数据并将其存储到一个变量,而不是把它们输出到页面,任何在 {capture name="foo"}和{/capture}之间的数据将被存储到 ...
- smarty内置函数、自定义函数
1.把字符串里的d字母替换成h格式:{'d'|str_replace:'h':$str}; d要查找的字符 h要替换的字符 $str字符串 2.function test($param){$p1=$p ...
- smarty内置函数
1.{append} 追加 2.{assign} 赋值 3.{block} 块 4.{call} 调用 5.{capture}捕获 6.{config_load}用来从配置文件中加载config变 ...
- Smarty内置函数之config_load
config_load的作用是: 用于从配置文件中加载变量,属性file引入配置文件名,另外若配置文件包含多个部分,可以使用属性section指定从那部分取得变量(若不指定,将会引入失败). 实例: ...
- 【Python全栈笔记】04 [模块二] 18 Oct lambda表达式, 内置函数
lambda表达式 lambda表达式是函数的一种简化,如下面两种函数定义方法,实际上效果是一样的. 使用lambda表达式的函数,func2是函数名,lambda: 后面的123 即为返回值. de ...
- Day4 内置函数补充、装饰器
li = [11,22,33,44]def f1(arg): arg.append(55)#函数默认返回值None,函数参数传递的是引用li = f1(li) print(li) 内置函数补充: ...
- 第四天 内置函数2 随机码 装饰器 迭代器、生成器 递归 冒泡算法 JSON
关于函数的return li = [11,22,33,44] def f1(arg): arg.append(55) li = f1(li) print(li) 因为li = f1(li) 实际赋值的 ...
- python面向对象的多态-类相关内置函数-类内置魔法函数-迭代器协议-上下文管理-04
多态 一种事物具备不同的形态 例如:水 --> 固态.液态.气态 多态:# 多个不同对象可以相应同一个对象,产生不同的结果 首先强调,多态不是一种特殊的语法,而是一种状态,特性(多个不同对象可以 ...
- 绑定与非绑定方法及反射,isinstance和issubclass内置函数
目录 绑定方法与非绑定方法 1.绑定方法 2.非绑定方法(staticmethod) isinstance和issubclass 内置函数 1.isinstance 2.issubclass 反射(面 ...
随机推荐
- POJ_3009——冰球,IDS迭代加深搜索
Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But th ...
- Maven Installation
OS:Ubuntu 14.04 Extract the distribution archive, i.e. apache-maven-3.2.2-bin.tar.gz to the director ...
- HBase的rowkey的设计原则
HBase是三维有序存储的,通过rowkey(行键),column key(column family和qualifier)和TimeStamp(时间戳)这个三个维度可以对HBase中的数据进行快速定 ...
- BootStrap——模态框
模态框(Modal)是BootStrap中很棒的一个插件.可以去BootStrap菜鸟驿站里面看看. 模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开 ...
- hibernate generator class="" id详解
“assigned” 主键由外部程序负责生成,在 save() 之前指定一个. “hilo” 通过hi/lo 算法实现的主键生成机制,需要额外的数据库表或字段提供高 ...
- lesson1:threadlocal的使用demo及源码分析
本文中所使用的demo源码地址:https://github.com/mantuliu/javaAdvance 其中的类Lesson1ThreadLocal 本文为java晋级系列的第一讲,后续会陆续 ...
- Nyoj 43 24 Point game 【DFS】
24 Point game 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描写叙述 There is a game which is called 24 Point game ...
- 最新的四款国外VPN,免费稳定,可以看国外网站的
tyle="margin-top:20px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Arial; ...
- Nested Class Templates
Templates can be defined within classes or class templates, in which case they are referred to as ...
- Mac下Qt连接MySQL 驱动问题
Mac OS X下Qt的mySQL driver编译安装 原创文章,采用CC协议发布,转载请注明: 转载自canX.me 本文链接地址: Mac OS X下Qt的mySQL driver编译安装 – ...