• Smarty 官网:

    http://www.smarty.net/
  • Smarty 下载:

    https://github.com/smarty-php/smarty/releases/tag/v3.1.30
// 下载 tar.gz 放到你的网站服务器中,和 jQuery和 Bootstrap 配合使用。
  • Smarty 使用例程

    // 假设 Smarty 框架已经解压在 /var/www 目录下,此目录是apache2 的家目录
// 现在,先写一个main.php
// main.php
<?php
include "smarty-3.1.30/libs/Smarty.class.php";
define ("__SITE_ROOT", "/var/www");
require_once('includes/include.php');
require_once('includes/functions.php'); $tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/"; // 指定模板目录
$tpl->compile_dir = __SITE_ROOT . "/templates_c/"; // 指定临时生成的网站目录
$tpl->config_dir = __SITE_ROOT . "/configs/"; // 指定配置文件目录
$tpl->cache_dir = __SITE_ROOT . "/cache/"; // 指定缓存目录,这个目录里面放着最终显示的网站php 文件
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
?>
    // 创建一些文件夹
mkdir templates templates_c configs cache
    // 编写模板
// vim templates/test.htm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
    // index.php  调用该模板
// vim index.php
<!DOCTYPE html>
<html>
<head>
</head> <body> <?php
require "main.php";
$tpl->assign("title", "test");
$tpl->assign("content", "test_1");
// 上面两行也可以用这行代替
// $tpl->assign(array("title" => "测试用的网页标题", "content" => "测试用的网页内容"));
$tpl->display('test.htm'); // 调用模板
?>
  • 显示效果:

最新文章

  1. 转-ArcGIS Engine中的License设置
  2. layer弹框
  3. RecyclerView解析--onViewDetachedFromWindow()/onViewAttachedToWindow()
  4. xtrabackup 增量备份(InnoDB)
  5. Fast portable non-blocking network programming with Libevent--转
  6. 算法专题训练 搜索a-T3 Ni骑士(ni)
  7. wireshark设置抓服务器的包
  8. 关于Thinkphp3.2版本的分页问题
  9. Resource temporarily unavailable用户的连接数设置的太小
  10. java篇 之 类型转化
  11. shelve模块,sys模块,logging模块
  12. php 会话控制(关于cookie的维护与生命周期)
  13. VS2012 中不能安装ARCGIS 10.0 SDK的解决方法
  14. QT之QML控件篇
  15. python命令行中import caffe报错的解决方案
  16. Java初学者的学习路线建议
  17. 读&lt;css世界&gt;笔记之img标签
  18. hdu-4725-The Shortest Path in Nya Graph-层次网络
  19. 数据库选型之内存数据库eXtremeDB
  20. BZOJ1965: [Ahoi2005]SHUFFLE 洗牌(exgcd 找规律)

热门文章

  1. java学习笔记6--类的继承、Object类
  2. [88221008]调用新下单接口失败,result:162020004,resInfo
  3. Ubuntu 64位安装32位运行库
  4. 转:VB用ADO连接SQLServer数据库
  5. Ajv JSON数据格式校验 使用
  6. JAVA实现zip压缩需要注意的问题
  7. linux 挂载 ISO 文件
  8. Jsp+Servlet+JavaBean经典MVC模式理解
  9. C# 实体集合和实体转换成相应的string、XDocument、XElement、XDocument
  10. CentOS6.5卸载默认安装的mysql5.1,并安装mysql5.5(亲测有效)