Discuz 模板引擎封装类功能与使用指南
主要功能概述
移除了对 Discuz 语言包的依赖支持
完整移植了 Discuz 模板原有的各项功能
引入了自动刷新缓存以及控制缓存生命周期的新特性
模板内的调用语法与原生 Discuz 保持一致,无需额外说明,仅需进行基础配置即可直接使用
如需恢复语言包功能,请解除 template.class.php 第 172 行的注释,并在 template.func.php 中添加 Discuz 原有的 languagevar 函数
点击此处下载源文件
以下是具体的代码示例:
/**
* 使用示例
*
* @copyright Copyright (c) 2007-2008 (http://www.tblog.com.cn)
* @author Akon(番茄红了)
* @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
*/
require_once ('classes/template.class.php');
$options = array(
'template_dir' => 'templates/', //指定模板文件存放目录
'cache_dir' => 'templates/cache', //指定缓存文件存放目录
'auto_update' => true, //当模板文件有改动时重新生成缓存 [关闭该项会快一些]
'cache_lifetime' => 1, //缓存生命周期(分钟),为 0 表示永久 [设置为 0 会快一些]
);
$template = Template::getInstance(); //使用单件模式实例化模板类
$template->setOptions($options); //设置模板参数
/*
// 可以使用以下三种方法设置参数
$template->setOptions(array('template_dir' => 'templates/default/')); //用于批量设置时使用
$template->set('template_dir', 'templates/default/');
$template->template_dir = 'templates/default/');
*/
$testArr = array('testa' => 'a', 'testb' => 'b');
include($template->getfile('test.htm'));
?>