zoukankan      html  css  js  c++  java
  • smarty配置及小实例

    smarty官网http://www.smarty.net/download下载最新版本的压缩包。然后解压。只需要其中的libs文件夹。放到自己的网站目录中。可以把libs任意重命名。此处我命名为Smarty。

    smarty目录结构:

    smarty配置(Smarty_conf.php):

    <?php
    
    //引入Smarty类文件
    include_once("Smarty/Smarty.class.php");
    
    //实例化Smarty类
    $smarty = new Smarty();
    
    $smarty->caching=false;
    
    //定义模版目录
    $smarty->template_dir = "./templates";
    
    //定义编译目录
    $smarty->compile_dir = "./templates_c";
    
    //定义缓存目录
    $smarty->cache_dir = "./smarty_cache";
    
    //定义模版解析的标签
    $smarty->left_delimiter = "{";
    
    $smarty->right_delimiter = "}";
    
    ?>

     index.php:

    <?php
    
    //引入smarty配置文件
    require './config/Smarty_conf.php';
    
    //模版变量赋值
    $smarty->assign('title','helloworld');
    
    $smarty->assign('content','最新版Smarty框架,测试页面');
    
    //打开对应模版
    $smarty->display('index.html');
    
    ?>

    对应的模版文件index.html:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{$title}</title>
    {literal}
    <style type="text/css">
        #content{
            width:500px;
            height:50px;
            margin:50px auto;
            border:#999999 1px solid;
            text-align: center;
            padding: 50px 80px;
        }
    </style>
    {/literal}
    </head>
        
    
    <body>
        <div id="content">{$content}</div>
    </body>
    </html>

    运行结果:

    smarty不是经常用到,有项目需求的时候会用。因此这里做个基本配置的记录。

  • 相关阅读:
    Leetcode#145 Binary Tree Postorder Traversal
    Leetcode#146 LRU Cache
    单引号和双引号的区别
    $* $@ $#
    pthread_detach
    pthread_join
    intent 启动activity、service的方法
    multicast based on udp
    ARM指令系统
    ARM寄存器
  • 原文地址:https://www.cnblogs.com/wenzichiqingwa/p/2668285.html
Copyright © 2011-2022 走看看