• smarty精品教程一(高级篇)


    学习php模板开发有一两天了,对比了一下。还是smarty模板功能强大一些。

    所以建议大家就学samrty模板吧!(个人观点)

    1.我们要配置好php环境

    2.下好samrty模板文件 下载地址->http://www.smarty.net/download.php

    3.smarty中文手册 下载地址->http://www.smarty.net/manual/en/(官方英文)

    http://www.hbcms.org.cn/main/smarty/index.html(中文)

    现在我们就可以学习smarty了.

    eg1:

    1.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("name", "fkedwgwy"); //进行模板变量替换

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

    i1.tpl

    {* 显示是smarty变量识符里的用*包含的文字为注释内容*}
    {include file="1/h1.tpl"}{*页面头*}
    <center>大家好,我叫{$name}, 欢迎大家阅读我的smarty学习材料。</center>
    {include file="1/f1.tpl"}{*页面尾*}

    h1.tpl

    <html>
    <head>
    <title>fkedwgwy---smarty教程</title>
    </head>
    <body>

    f1.tpl

    <hr>
    <center> fkedwgwy作品------smarty教程 </center>
    <hr>
    </body>
    </html>

    ouiprint:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0037)http://127.0.0.1/smartyer/a/php/1.php -->
    <HTML><HEAD><TITLE>fkedwgwy---smarty教程</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <META content="MSHTML 6.00.3790.4237" name=GENERATOR></HEAD>
    <BODY>
    <CENTER>大家好,我叫fkedwgwy, 欢迎大家阅读我的smarty学习材料。</CENTER>
    <HR>

    <CENTER>fkedwgwy作品------smarty教程 </CENTER>
    <HR>
    </BODY></HTML>

    这就是第一个smarty实例`````

    很简单吧```

  • 相关阅读:
    题解 P5996 【[PA2014]Muzeum】
    题解 CF1433G 【Reducing Delivery Cost】
    题解 CF1430E 【String Reversal】
    题解 CF710F 【String Set Queries】
    题解 P4334 【[COI2007] Policija】
    LIS 树状数组优化
    离散化模板
    P4309 [TJOI2013]最长上升子序列
    p3902 递增(incr)
    poj3417 暗的连锁
  • 原文地址:https://www.cnblogs.com/fengju/p/6174140.html
Copyright © 2020-2023  润新知