Twig without using symfony

I can not find information on using branches without Symfony2. I want to use a branch on my custom webpage without symfony border. Is it possible? Maybe someone can suggest another templating "system" or a good way to avoid html from php?

+4
source share
1 answer

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
+12
source

Source: https://habr.com/ru/post/1615088/


All Articles