• 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
  • 相关阅读:
    JS常见面试题总结-真实被问到的!
    今天给大家分享一下js中常用的基础算法
    小程序创建自定义组件
    JavaScript里面9种数组遍历!
    第七章 restframework——url控制器
    第三章 Linux——目录结构
    第二章 Linux——基础命令使用
    第一章 Linux——系统介绍及环境搭建
    第六章 restframework——认证组件、权限组件、频率组件
    第五章 restframework——解析器
  • 原文地址:https://www.cnblogs.com/wangkongming/p/3003190.html
Copyright © 2020-2023  润新知