zoukankan      html  css  js  c++  java
  • smarty精品教程二(高级篇)

    上面我们学习了,第一个实例.大家都有所了解了.

    接下来我们学习第二个实例.主要是学习smarty的一些函数.

    eg2:

    2.php

    <?php
    /*********************************************
    QQ:283093141

    *********************************************/
    include_once('../libs/Smarty.class.php');   //包含smarty类文件

    $smarty= new Smarty;  //实例化Smarty类

    $smarty->template_dir= './templates';  //设置模板目录
    $smarty->compile_dir= './templates_c';      //设置编译目录
    $smarty->cache_dir= './cache';              //设定缓存目录
    $smarty->caching = ture;
    //----------------------------------------------------
    //左右边界符,默认为{},但实际应用当中容易与JavaScript
    //相冲突,所以建议设成<{}>或其它。
    //----------------------------------------------------
    $smarty->left_delimiter = "{";
    $smarty->right_delimiter = "}";

    $smarty->assign("str1", "my name is xiao jun, li."); //将str1替换成My Name Is Xiao Jun, Li.
    $smarty->assign("str2", "我的名字叫:"); //输出: 我的名字叫:李晓军
    $smarty->assign("str3", "公元"); //输出公元2004年8月21日(我的当前时间)
    $smarty->assign("str4", ""); //第四句不处理时会显示默认值,如果使用前面这一句则替换为""
    $smarty->assign("str5", "前边8个*"); //第五句输出:********前边8个*
    $smarty->assign("str6", "TEACHerLI@163.com"); //这里将输出teacherli@163.com
    $smarty->assign("str7", "this is teacherli"); //在模板中显示为:this is 李晓军
    $smarty->assign("str8", "HERE IS COMBINING:");

    //编译并显示位于./templates下的index.tpl模板
    $smarty->display("2/2.tpl");
    ?>

    2.tpl

    <html>
    <head><title>大师兄smarty示例2</title></head>
    <body>
    1. 第一句首字母要大写:{$str1|capitalize}<br>
    2. 第二句模板变量 + 李晓军:{$str2|cat:"李晓军"}<br>
    3. 第三句输出当前日期:{$str3|date_format:"%Y年%m月%d日"}<br>
    4. 第四句.php程序中不处理,它显示默认值:{$str4|default:"没有值!"}<br>
    5. 第五句要让它缩进8个空白字母位,并使用"*"取替这8个空白字符:<br>
    {$str5|indent:8:"*"}}<br>
    6. 第六句把TEACHerLI@163.com全部变为小写:{$str6|lower}<br>
    7. 第七句把变量中的teacherli替换成:李晓军:{$str7|replace:"teacherli":"李晓军"}<br>
    8. 第八句为组合使用变量修改器:{$str8|capitalize|cat:"这里是新加的时间:"|date_format:"%Y年%m月%d日"|lower}
    </body>
    </html>

    outprint:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0037)http://127.0.0.1/smartyer/a/php/2.php -->
    <HTML><HEAD><TITLE>大师兄smarty示例2</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <META content="MSHTML 6.00.3790.4237" name=GENERATOR></HEAD>
    <BODY>1. 第一句首字母要大写:My Name Is Xiao Jun, Li.<BR>2. 第二句模板变量 + 李晓军:我的名字叫:李晓军<BR>3.
    第三句输出当前日期:2008年05月13日<BR>4. 第四句.php程序中不处理,它显示默认值:没有值!<BR>5.
    第五句要让它缩进8个空白字母位,并使用"*"取替这8个空白字符:<BR>********前边8个*}<BR>6.
    第六句把TEACHerLI@163.com全部变为小写:teacherli@163.com<BR>7.
    第七句把变量中的teacherli替换成:李晓军:this is 李晓军<BR>8. 第八句为组合使用变量修改器:2008年05月13日
    </BODY></HTML>

    学到这里,我们就掌握了一些smarty的基本操作和方法的运用了.

    加油````

  • 相关阅读:
    手势识别 ios
    无题
    核心动画笔记
    Quartz2D的学习2
    Quartz2D的学习1
    NSURLsessionTask
    NSURLSession
    POST请求的两种方式
    网络第一天
    NSThread
  • 原文地址:https://www.cnblogs.com/fengju/p/6174139.html
Copyright © 2011-2022 走看看