如何让 Twig 将 HTML 输出写入文件,而不是浏览器? [英] How let Twig write the HTML output to a file, instead to a browser?

查看:9
本文介绍了如何让 Twig 将 HTML 输出写入文件,而不是浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要渲染的 Twig 模板(.html 文件)(用我的 PHP 文件中的值替换标记).但是,我不想将渲染结果发送到浏览器,而是将其写入新的 .html 文件.我想 Django 模板的解决方案也类似.

I have a Twig template (.html file) that I want to render (replace the tokens with values from my PHP file). Instead of sending the rendered result to a browser, however, I want to write it to a new .html file. I would imagine the solution would also be similar for a Django template.

我如何在 PHP 中做到这一点?

How can I do this in PHP?

推荐答案

您可以将渲染的输出分配给一个变量,然后随心所欲地使用它.

You can get the rendered output assigned to a variable and then do with it what you please.

$bob = $this->render('MyBundle:index.html.twig',[
            'foo' => $foo,
            'token' => $token
        ]);
dump($bob->getContent());exit(0);

这篇关于如何让 Twig 将 HTML 输出写入文件,而不是浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆