php模板twig使用

首先安装composer,
确保php是版本7

然后composer.json
{
    "require": {
        "twig/twig": "2.4.3"
    }
}


然后composer Install。

现在


确保public是nginx的文档根目录。

index.php
<?php
require ("../vendor/autoload.php");
$loader = new Twig_Loader_Filesystem('../tpl');
$twig = new Twig_Environment($loader, array(
		'cache' => '../cache',
		'auto_reload'=>true,
));
echo $twig->render('1.tpl', array('name' => '张三'));


1.tpl
hello, {{ name }}!


打开浏览器,
localhost/index.php
显示
hello,张三!

猜你喜欢

转载自xieye.iteye.com/blog/2379462