在没有 Symfony 的情况下使用 Twig [英] Twig using without Symfony
本文介绍了在没有 Symfony 的情况下使用 Twig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没有找到有关在没有 Symfony 的情况下使用 twig 的任何信息.我想在没有 symfony 框架的情况下在我的自定义网页中使用 twig.可能吗?
I don't find any information about using twig without Symfony. I want to use twig in my custom web page without symfony framework. Is it possible?
推荐答案
给你一个可运行的示例:
To give you a runnable sample:
在空项目中安装 Twig:
Install Twig in empty project:
composer require "twig/twig:^3.0"
创建以下test.php";文件:
Create the following "test.php" file:
<?php
require_once('vendor/autoload.php');
$loader = new \Twig\Loader\FilesystemLoader('./templates');
$twig = new \Twig\Environment($loader);
echo $twig->render('demo.twig', ['name' => 'Fabien']);
创建视图:
Create the view:
mkdir templates
cd templates
echo "Hello, {{ name }}!" > demo.twig
运行演示:
Run the demo:
cd ..
php test.php
这篇关于在没有 Symfony 的情况下使用 Twig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文