zoukankan      html  css  js  c++  java
  • smarty 截取字符串,调用php中的方法,foreach循环

    1.smarty截取字符串

          html中的代码    <{$content|truncate:30:"..."}> 

                                     将$content字符串截取30个字符,后面的内容用 "..." 来代替

     

    2.smarty调用php中的方法

            html中的代码      <{$content|sub}>

                                               将$content字符窜当成变量传递给php中的方法sub (这里的php页面是display html页面的php页面)

             php中的代码          <?php

                                                     function sub($con){

                                                              return "123";

                                                     }

                                                ?>

              如果要传递多个参数给php页面中的方法

               html中的代码      <{$content|sub:"aa":"bb"}>  aa和bb是第二和第三个参数

                                               将$content字符窜当成变量传递给php中的方法sub (这里的php页面是display html页面的php页面)

               php中的代码          <?php

                                                     function sub($con,$aa,$bb){

                                                              return "123";

                                                     }

                                                ?>

    3.foreach循环

              <{foreach item=arr from=$row}>   $row是从php页面传递过来的数组 

                    <span><{$arr.name}></span>

             <{/foreach}>

  • 相关阅读:
    【24.17%】【codeforces 721D】Maxim and Array
    【26.42%】【codeforces 745C】Hongcow Builds A Nation
    【67.24%】【codeforces 745A】Hongcow Learns the Cyclic Shift
    【37.50%】【codeforces 745B】Hongcow Solves A Puzzle
    【78.89%】【codeforces 746A】Compote
    【75.28%】【codeforces 764B】Decoding
    【30.43%】【codeforces 746C】Tram
    【21.58%】【codeforces 746D】Green and Black Tea
    四种生成和解析XML文档的方法详解(介绍+优缺点比较+示例)
    xml常用四种解析方式优缺点的分析×××××
  • 原文地址:https://www.cnblogs.com/james1207/p/3315505.html
Copyright © 2011-2022 走看看