To give you an executable sample,
1) install Twig:
mkdir test
cd test
composer require twig/twig
2) Create the following test.php file:
<?php
require_once("vendor/autoload.php");
$loader = new \Twig_Loader_Filesystem(__DIR__.'/templates');
$twig = new \Twig_Environment($loader);
echo $twig->render('demo.twig', ['name' => 'zhinyz']);
3) create a view
mkdir templates
cd templates
echo "Hello, {{ name }}!" > demo.twig
4) Run the demo:
cd ..
php test.php
source
share