`
varsoft
  • 浏览: 2439328 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

smarty if 逻辑运算符

阅读更多

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

 

 

 

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

这是一个表格中增加一行的方法,意思是有4列,如果够四列就换新行,具体的以后会讲到。

分享到:
评论

相关推荐

    smarty运算符

    php5会使用的smarty运算符,smarty是在php前期使用中常见的模版分离,同时国内鼎鼎大名的ecshop也是采用这样方式开发系统

    delphi强大html模板引擎(类似smarty) 逻辑与界面分离.zip

    delphi强大html模板引擎(类似smarty) 逻辑与界面分离

    Smarty

    Smarty Smarty Smarty

    smarty模板中文手册

    1. 速度:采用Smarty编写的程序可以获得最大速度的提高,这一点是相对于其它的模板引擎技术而言的。...5. 模板中可以使用if/elseif/else/endif。在模板文件使用判断语句可以非常方便的对模板进行格式重排。

    smarty安装与入门

    smarty安装及初级使用 在PHP的世界里已经出现了各式各样的模板类,但就功能和速度来说Smarty还是一直处于领先地位,因为Smarty的功能相对强大,所以使用起来比其他一些模板类稍显复杂了一点。现在就用30分钟让您...

    PHP-Smarty模板笔记

    Smarty分离了逻辑代码和外在的内容,提供一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。Smarty工作的目的是要使PHP程序员同前端人员分离,使程序员改变程序的逻辑内容不会影响到前端...

    Smarty最新版下载自Smarty官网

    Smarty最新版官网,Smarty最新版下载自Smarty官网

    smarty3.0,smarty最新版本

    smarty3.0,smarty最新版本

    smarty3 的应用详解

    $smarty= Smarty::instance(); 模板 之前的smarty模板,相当于重新定义了一套标签语言,那么smarty3提供了一种新的模板形式,直接支持php语法的模板。 但是问题就出来了,我们还有必要用模板吗? 引用php类型模板...

    Smarty_smarty_

    Smarty 模板引擎教程,内容主要有基本语法、变量、组合修改器、内建函数、自定义函数、配置文件、控制台调试、缓存、插件扩展、使用技巧和经验等,比较详细的一个中文手册

    php模版 (smarty)php模版 (smarty)php模版 (smarty)

    php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)

    smarty手册.chm

    if,elseif,else ldelim,rdelim literal php section,sectionelse strip 8. Custom Functions [自定义函数] assign counter cycle debug eval fetch html_checkboxes html_image html_options ...

    smarty-3.1.29

    2015年12月24日最新版:smarty-3.1.29

    smarty-中文文档

    更准确的说,它分开了逻辑程序和外在的内容,提供了一种易于管理的方法。可以描述为应用程序员和美工扮演了不同的角色,因为在大多数情况下 ,他们不可能是同一个人。例如,你正在创建一个用于浏览新闻的网页,新闻标题,...

    Smarty中文手册,Smarty教程,Smarty模板的入门教材

    Smarty - the compiling PHP template engine的译文版本,高清版。 Smarty 是一个php 模板引擎。更准确的说,它分开了逻辑程序和外在的内容,提供了一种易于管理的方法。

    smarty模板,调用静态页面模板,Smarty-2.6.22

    smarty模板,调用静态页面模板,Smarty-2.6.22

    Smarty-v3.1.13

    Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。简单的讲,目的就是...

    php+smarty输出新闻列表

    php+smarty输出资讯列表,生成html静态

    Smarty软件包Smarty-3.0b7.tar.gz

    smarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分 离,使用的程序员改变程序的逻辑内容不会影响到美工的页面设计,美工重新修改页面不会影响...

    Smarty-2.6.26.tar.gz

    Smarty 最好用的PHP模板 Smarty是一个使用PHP写出来的模板PHP模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP...

Global site tag (gtag.js) - Google Analytics