zoukankan      html  css  js  c++  java
  • Smarty中的修饰函数

    smarty中的修饰函数:

      对在模板文件中显示的数据变量进行二次修饰。

      格式:

        {ts:变量|函数名:参数1:参数2:参数3...|函数名:参数1:参数2...} 

      常见的修饰函数:

        capitalize:首字母大写

        count_characters:统计字符数

        count_words():统计单词数

        date_format:日期设置

        default:默认值

        indent:缩进

        lower:小写

        upper:大写

        nl2br:将换行符转换成br

        replace:字符串替换

        strip_tags:去掉html代码标签

        truncate:字符串截取 

      【modify.php】

    <?php
    require_once("./smarty.inc.php");
    $str = "this is my page";
    $time = time(); 
    $nl2br = "that 
    is cat.";  //将换行符转换成br
    $html = "<h1>this is strip_tags</h1>";
    $tpl -> assign("str",$str);
    $tpl -> assign("time",$time);
    $tpl -> assign("nl2br",$nl2br); 
    $tpl -> assign("html",$html);
    $tpl -> display("modify.html");
    ?>

      【modify.html】

    {ts:$str}<br/>
    capitalize:{ts:$str|capitalize}
    <hr/>
    {ts:$str}<br/>
    count_characters:{ts:$str|count_characters:true}
    <hr/>
    {ts:$str}<br/>
    count_words:{ts:$str|count_words}
    <hr/>
    {ts:$time}<br/>
    date_format:{ts:$time|date_format:"Y-m-d"}
    <hr/>
    {ts:$smarty.session.username}<br/>
    default:{ts:$smarty.session.username|default:"<a href=''>登录/注册</a>"}
    <hr/>
    {ts:$str}<br/>
    {ts:$str|indent:10}
    <hr/>
    {ts:$str}<br/>
    {ts:$str|upper|lower}
    <hr/>
    {ts:$nl2br}<br/>
    {ts:$nl2br|nl2br}
    <hr/>
    {ts:$str}<br/>
    {ts:$str|replace:"i":"*"}
    <hr/>
    {ts:$html}<br/>
    {ts:$html|strip_tags}
    <hr/>
    {ts:$str}<br/>
    {ts:$str|truncate:10:""}
    <hr/>
    <hr/>

    #在modify.php中获取前台modify.html中的值#

  • 相关阅读:
    apex Error : Given no hashes to check 137 links for project 'pip': discarding no candidates
    源码编译pytorch-1.2.0
    proxychains
    git简单教程
    caffe ssd + cuda9.0
    ros+pcl error recoder
    硬盘挂载
    opencv3.4.1+ubuntu18.04+anaconda 源码编译
    从RocksDBStateBackend讲述Flink的State机制
    由Rocksdb状态后端引出的Tree的应用
  • 原文地址:https://www.cnblogs.com/shuo-128/p/6869102.html
Copyright © 2011-2022 走看看