科技张
hollo

我在本地找这个自动文件,也没有找到、、、、
Jonty1024
public function display($file)
{
$file = APP . '/views/' . $file;
if(is_file($file)) {
$loader = new \Twig\Loader\FilesystemLoader(APP . '/views');
$twig = new \Twig\Environment($loader, [
'cache' => '/path/to/compilation_cache',
'debug' => DEBUG
]);
$template = $twig->load('index.html');
$template->display($this->assign?$this->assign:"");
}
}这样就可以了,版本是2.x的
qq_你可懂我_0
$loader = new \Twig\Loader\FilesystemLoader(APP . '/view');
$twig = new \Twig\Environment($loader, [
'cache' => APP . '/runtime/cache',
'debug' => DEBUG,
]);
$template = $twig->load("$dir/$file.html");
echo $template->render($this->var_list);
qq_零点_19
不传assign的时候为空,报错了,对传来的值进行判断,三元运算。不传值的时候为空串或者空数组,看情况
hanwudideweiqun
你代码打错了
Kevin_裴
里面有集成模板引擎,twig
qq_铁路边老徐_03212768
应该可以在配置中改吧
mir_gong
这位同学看的很用心哈,后面的课程我偷偷改了
墨灵
传参容易导致耦合变高,不过只要你开心,改成传参也行