zoukankan      html  css  js  c++  java
  • 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实例`````

    很简单吧```

  • 相关阅读:
    Windows 10安装Docker并使用私钥连接AWS EC2
    Logback中%X的使用
    使用CompletableFuture+ExecutorService+Logback的多线程测试
    Spring Boot与Spring Session集成
    Java 8中Collection转为Map的方法
    记一次OutOfMemory定位过程-续
    记一次OutOfMemory定位过程
    Jmeter学习之While Controller
    使用VirtualBox虚拟机搭建局域网(续)
    Java 8的Lambda学习
  • 原文地址:https://www.cnblogs.com/fengju/p/6174140.html
Copyright © 2011-2022 走看看