zoukankan      html  css  js  c++  java
  • smarty 模板编译和变量调节器 模板引入

    <?php
    require './smarty/Smarty.class.php';
    $sm = new Smarty;
    //$sm->force_compile = true;
    $sm->setTemplateDir("./dir");//设置模板路径
    
    $sm->assign('k','JaKLfhs');
    $sm->display('4.html');//输出
    //echo $sm->fetch('4.html');//输出
    //Smarty的一个特点,先编译成.php文件,再执行该php //Smarty在第一次运行的时候,稍慢,包含了编译模板+包含执行 //后面的运行中速度会快,因为直接包含PHP文件. //会根据模板修改的时间重新编译模板 //html就是模板,根据Html修改的时间 //创建模板->编译模板->修改模板->再次编译 //如果想强制编译:比如在开发过程中 可以 force_compile=true强制编译,这样每次执行就编译
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    {$k|upper}<br>
    {$smarty.now|date_format:'%Y-%m-%d'}<br>
    {$smarty.now|date_format:'Y-m-d'}
    </body>
    </html>

     模板引入:

    {include file="head.html"}
    <h1>
        {$k|upper}<br>
        {$smarty.now|date_format:'%Y-%m-%d'}<br>
        {$smarty.now|date_format:'Y-m-d'}
    </h1>
    {include file="footer.html"}
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        哈哈,我是头部

    footer.html:

    哈哈,我是尾部
    </body>
    </html>
  • 相关阅读:
    列表
    break和continue
    第三天下午
    第二天
    简历,面试
    周三&nbsp;景安
    应届生求职优势(我的求职心…

    2013年01月02日
    Click&nbsp;and&nbsp;Drag
  • 原文地址:https://www.cnblogs.com/as3lib/p/6488729.html
Copyright © 2011-2022 走看看