Home  >  Article  >  Backend Development  >  discuz template Discuz template engine encapsulation class code

discuz template Discuz template engine encapsulation class code

WBOY
WBOYOriginal
2016-07-29 08:38:221159browse

Main function description
Removed the Discuz language pack function
Transplanted all the functions in the Discuz template
Added automatic update cache and life cycle functions
The usage method in the template is the same as that of Discuz, so there will be no redundant explanation , you only need to make some simple settings before use. If you need to use the language pack function of discuz, just remove the comment on line 172 of template.class.php and add the original languagevar function of discuz in template.func.php That’s it
Click to download the source file
The following is a code example:
/**
* Usage example
*
* @copyright Copyright (c) 2007-2008 (http://www.tblog.com.cn)
* @author Akon(tomato is red)
* @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/', //Specify the directory where template files are stored
'cache_dir' => 'templates/cache', //Specify the directory where cache files are stored
'auto_update' => true, //Regenerate the template file when it is changed Cache [Turn off this item will be faster]
'cache_lifetime' => 1, //Cache life cycle (minutes), 0 means permanent [Set to 0 will be faster]
);
$template = Template::getInstance (); //Use singleton mode to instantiate the template class
$template->setOptions($options); //Set template parameters
/*
// You can use the following three methods to set parameters
$template-> setOptions(array('template_dir' => 'templates/default/')); //Use for batch settings
$template->set('template_dir', 'templates/default/');
$template ->template_dir = 'templates/default/');
*/
$testArr = array('testa' => 'a', 'testb' => 'b');
include($template-> ;getfile('test.htm'));
?>

The above introduces the encapsulation class code of discuz template Discuz template engine, including the content of discuz template. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn