smarty模版--if操作符
1,smarty模版中if的⽤法
<?php
smarty模板引擎缓存原理$root=str_replace("\\","/",dirname(__FILE__));
define("ROOT",$root."/");
define("DOMAIN","localhost/testSmarty");
require(ROOT."smarty/Smarty.class.php");
$smarty=new Smarty();
$smarty->template_dir=ROOT."demo/templates/";
$smarty->compile_dir=ROOT."demo/templates_c/";
$smarty->use_sub_dirs=false;
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->caching="0";
$smarty->cache_dir=ROOT."demo/caches/";
$smarty->cache_lifetime=3*24*(60*60);//0
$smarty->assign("num",33);
$smarty->display("testif.html");
?>
模版⽂件:testif.html
<{if $num eq 22}>
这部分执⾏了22
<{elseif $num eq 33}>
这部分执⾏了33
<{else}>
没有输出任何东西
<{/if}>
2,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
if $_global_password} 是判断变量存不存在....
{if $_global_password!==''} 是判断变量等不等于空....
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:被。。。除
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论