zoukankan      html  css  js  c++  java
  • smarty模版if操作符

    1,smarty模版中if的用法

    <?php
    $root=str_replace("\\","/",dirname(__FILE__));
    define("ROOT",$root."/");
    define("DOMAIN","http://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:被。。。除

    千里之行,始于足下。改变现在,就是改变未来。改变未来,从现在开始。 个人网站:http://www.wangkongming.cn
  • 相关阅读:
    套接字和域名系统DNS
    TCP滑动窗口控制流量的原理
    AngularJS 路由
    使用纯前端JavaScript 实现Excel IO
    Deferred在jQuery和Angular中的使用与简单实现
    深入理解函数声明和函数表达式(转)
    Visual Studio Code 智能提示文件
    JavaScript框架设计(四) 字符串选择器(选择器模块结束)
    JavaScript框架设计(三) push兼容性和选择器上下文
    canvas学习和面向对象(二)
  • 原文地址:https://www.cnblogs.com/wangkongming/p/3003190.html
Copyright © 2011-2022 走看看