function TemplateLite($templateFile, $templateVar, $charset, $varPrefix = '') { $templateFile = substr($templateFile, strlen(TMPL_PATH)); include_once "class.template.php"; $tpl = new Template_Lite(); $tpl->template_dir = TMPL_PATH; $tpl->compile_dir = CACHE_PATH; $tpl->cache_dir = TEMP_PATH; $tpl->assign($templateVar); $tpl->display($templateFile); return; }
/** * @see RO_Flow_Work::_run() * * @return RO_Flow_Work */ protected function _run() { $this->_setNext('NEXT'); if (!isset($this->_data['_VIEW_DATA_'])) { return; } $data = $this->_data['_VIEW_DATA_']; $tpl = str_replace('_', DIRECTORY_SEPARATOR, $this->_data['_VIEW_']) . $this->_params['suffix']; $tplite = new Template_Lite(); $tplite->template_dir = $this->_params['tpl_path']; $tplite->compile_dir = $this->_params['tplc_path']; $tplite->cache = false; $tplite->force_compile = true; $tplite->assign($data); $tplite->display($tpl); }
/** * 渲染模板输出 * @access public * @param string $templateFile 模板文件名 * @param array $var 模板变量 * @return void */ public function fetch($templateFile, $var) { vendor("TemplateLite.class#template"); $templateFile = substr($templateFile, strlen(THEME_PATH)); $tpl = new \Template_Lite(); $tpl->template_dir = THEME_PATH; $tpl->compile_dir = CACHE_PATH; $tpl->cache_dir = TEMP_PATH; if (C('TMPL_ENGINE_CONFIG')) { $config = C('TMPL_ENGINE_CONFIG'); foreach ($config as $key => $val) { $tpl->{$key} = $val; } } $tpl->assign($var); $tpl->display($templateFile); }
<?php $timeparts = explode(" ", microtime()); $starttime = $timeparts[1] . substr($timeparts[0], 1); require "../src/class.template.php"; $tpl = new Template_Lite(); $tpl->force_compile = true; $tpl->compile_check = true; $tpl->cache = false; $tpl->cache_lifetime = 3600; $tpl->config_overwrite = false; $tpl->assign("Name", "Fred Irving Johnathan Bradley Peppergill"); $tpl->assign("FirstName", array("John", "Mary", "James", "Henry")); $tpl->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), array("phone" => "555-5555", "fax" => "555-4444", "cell" => "555-3333"))); $tpl->assign("bold", array("up", "down", "left", "right")); $tpl->assign("lala", array("up" => "first entry", "down" => "last entry")); $tpl->display("index.tpl"); $timeparts = explode(" ", microtime()); $endtime = $timeparts[1] . substr($timeparts[0], 1); echo bcsub($endtime, $starttime, 6);