一篇简短的介绍
<?php
require_once "../vendor/autoload.php";
use Twig\Environment;
$loader = new \Twig\Loader\ArrayLoader([
'index' => 'Hello {{ name }}!',
]);
$twig = new \Twig\Environment($loader);
$twig = new Environment($loader, array(
'cache' => 'cache',
'auto_reload' => true, //根据文件更新时间,自动更新缓存
'debug' => true
));
echo $twig->render('index', ['name' => 'Fabien']);
$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader, [
'cache' => 'cache',
'auto_reload' => true, //根据文件更新时间,自动更新缓存
'debug' => true
]);
echo $twig->render('hello', ['name' => 'Sanli']);
echo "<br>——————————————— Chain ——————————————— <br>";
$loader1 = new \Twig\Loader\ArrayLoader([
'base.html' => '{% block content %}{% endblock %}',
]);
$loader2 = new \Twig\Loader\ArrayLoader([
'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}',
'base.html' => 'Will never be loaded',
]);
$loader = new \Twig\Loader\ChainLoader([$loader1, $loader2]);
$twig = new \Twig\Environment($loader, [
'cache' => 'cache',
'auto_reload' => true, //根据文件更新时间,自动更新缓存
'debug' => true
]);
echo $twig->render('index.html', ['name' => 'Sanli']);
网友评论