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}>

  • 相关阅读:
    [Algorithm] Universal Value Tree Problem
    [HTML5] Using the focus event to improve navigation accessibility (nextElementSibling)
    [Javascript] Coding interview problem: Scheduler functional way
    [Algorithm] Tree: Lowest Common Ancestor
    [NPM] Execute Code from a Remote GitHub Branch with npx
    hdu 4740
    通过网页实现软件的布局
    STL 统计vector容器中指定对象元素出现的次数:count()与count_if()算法
    善待自己生存的空间
    青春散场
  • 原文地址:https://www.cnblogs.com/james1207/p/3315505.html
Copyright © 2011-2022 走看看