zoukankan      html  css  js  c++  java
  • smarty模板的内置函数

    内置函数参考:http://www.php100.com/manual/smarty/language.builtin.functions.html

    主要就是 foreach 和 if elseif else
     
    直接上代码把,很多注意点都写在代码里面了。
     1 <!doctype html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6     <style type="text/css">
     7     </style>
     8     <link rel="stylesheet" href="css/css_base.css">
     9 </head>
    10 <body >
    11     <h1>内建函数的使用</h1>
    12     <h2>取出普通的索引数组</h2>
    13     <h3>foreach函数循环取出,添加到用户列表中</h3>
    14     <ul>        
    15     <{foreach from = $ff item = temp key= k}>
    16         <li><{$k}>=<{$temp}></li>
    17     <{/foreach}>        
    18     </ul>
    19     备注:foreach函数后台有函数支持。其实后台就是一个foreach(){}函数。
    20     from表示循环访问的数组,item当前元素的变量名 key 表示 当前键名的变量名
    21     <h2>取出1维关联数组</h2>
    22     <ul>
    23         <{foreach from = $gg item = temp key = key}>
    24             <li><{$key}>=<{$temp}></li>
    25         <{/foreach}>
    26     </ul>
    27     <h2>取出2维索引数组</h2>
    28     <ul>
    29         <{foreach from = $hh item = temp key = key}>
    30             <li><{$key}>=<{$temp[0]}></li>
    31         <{/foreach}>
    32     </ul>
    33     <h2>取出2维关联数组</h2>
    34     <ul>
    35         <{foreach from = $ii item = temp}>
    36             <{* 二次循环 *}>
    37             <{foreach from = $temp item = val key = key}>
    38             <li><{$key}>=<{$val}></li>
    39             <{/foreach}>
    40         <{/foreach}>
    41     </ul>
    42     备注:当数组是关联数组的时候最好用上k<br />第二次循环的时候from应该取第一次中的item值。
    43 
    44     //练习
    45     <h2>练习 人物信息</h2>
    46     一:
    47     <ul>        
    48         <{foreach from = $mm item = temp}>
    49             <{* 二次循环 *}>
    50             <{foreach from = $temp item = val key = key}>
    51             <{if $val <= 2}>
    52             <li><{$key}>=<{$val}></li>
    53             <{/if}>
    54             <{/foreach}>
    55         <{/foreach}>        
    56     </ul>
    57     二:
    58     <ul>        
    59         <{foreach from = $mm item = temp}>
    60             <{* 二次循环 *}>
    61             <{foreach from = $temp item = val key = key}>
    62             <{if $key != 'age'}>
    63             <li><{$key}>=<{$val}></li>
    64             <{/if}>
    65             <{/foreach}>
    66         <{/foreach}>        
    67     </ul>
    68     <!-- if elseif else -->
    69     <h1>if else</h1>
    70     <{if $bb > 600}>
    71     bb 大于11 600
    72     <{else}>
    73     bb 小w于600
    74     <{/if}>
    75 
    76     <!-- //嵌套循环 -->
    77     <ul>
    78         <{foreach from = $hh item = temp key = key}>
    79         <{*temp是一维数组*}>
    80             <{foreach from = $temp item = val}>
    81                 <li><{$val}></li>
    82             <{/foreach}>
    83         <{/foreach}>
    84     </ul>
    85     <script src="js/js_base.js"></script>
    86 </body>
    87 </html>
    学透前端行业所有技术,玩遍北京周边所有城市。然后我会回到那个生我养我的地方,因为有亲人的地方才是家。
  • 相关阅读:
    int **指针问题
    用 _tcscmp 替代 strcmp 或 wcscmp
    C++经典面试算法题
    目标世界上最小的Linux系统—ttylinux体验
    im-switch -s ibus错误:Error: no configuration file "ibus" exists.
    Ruby环境搭建
    emulator: ERROR: x86 emulation currently requires hardware acceleration!Please ensure Intel HAXM is properly installed and usable.CPU acceleration status: HAX kernel module is not installed!
    POJ 1007 DNA Sorting
    POJ 1002 487-3279
    Ubuntu Android adb调试无法识别设备 -- List of devices attached ???????????? no permissions
  • 原文地址:https://www.cnblogs.com/snowinmay/p/3173914.html
Copyright © 2011-2022 走看看