在没有 Symfony 的情况下使用 Twig

编程入门 行业动态 更新时间:2024-10-28 00:14:40
本文介绍了在没有 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

    本文发布于:2023-11-16 21:24:14,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1607517.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:情况下   Symfony   Twig

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!