唐金木 07e2592bdb first commit | 4 years ago | |
---|---|---|
.. | ||
src | 4 years ago | |
.gitignore | 4 years ago | |
LICENSE | 4 years ago | |
README.md | 4 years ago | |
composer.json | 4 years ago |
基于XML和标签库的编译型模板引擎
composer require topthink/think-template
<?php
namespace think;
require __DIR__.'/vendor/autoload.php';
// 设置模板引擎参数
$config = [
'view_path' => './template/',
'cache_path' => './runtime/',
'view_suffix' => 'html',
];
$template = new Template($config);
// 模板变量赋值
$template->assign(['name' => 'think']);
// 读取模板文件渲染输出
$template->fetch('index');
// 完整模板文件渲染
$template->fetch('./template/test.php');
// 渲染内容输出
$template->display($content);
支持静态调用
use think\facade\Template;
Template::config([
'view_path' => './template/',
'cache_path' => './runtime/',
'view_suffix' => 'html',
]);
Template::assign(['name' => 'think']);
Template::fetch('index',['name' => 'think']);
Template::display($content,['name' => 'think']);
详细用法参考开发手册