确保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,张三!