-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmarty.php
More file actions
39 lines (31 loc) · 1.04 KB
/
smarty.php
File metadata and controls
39 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use Soli\View;
use Soli\View\Engine\Smarty as SmartyEngine;
include __DIR__ . "/../vendor/autoload.php";
$config = [
'viewsDir' => __DIR__ . '/views/smarty/',
'viewsCacheDir' => __DIR__ . '/cache/templates/',
'viewsCompileDir' => __DIR__ . '/cache/templates_c/',
];
$view = new View();
$view->setViewsDir($config['viewsDir']);
$view->setViewExtension('.tpl');
// 通过匿名函数来设置模版引擎,延迟对模版引擎的实例化
$view->setEngine(function () use ($config, $view) {
$engine = new SmartyEngine($view);
// 开启 debug 不进行缓存
$engine->setDebug(true);
$engine->setOptions([
'compile_dir' => $config['viewsCompileDir'],
'cache_dir' => $config['viewsCacheDir'],
'caching' => true,
'caching_type' => 'file',
'cache_lifetime' => 86400,
'left_delimiter' => '{{',
'right_delimiter' => '}}',
]);
return $engine;
});
$view->setVar('name', 'Soli');
$template = 'home/index';
echo $view->render($template);