在 Twig 中禁用格式 [英] Disable formatting in Twig
本文介绍了在 Twig 中禁用格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 Twig 模板中有变量 source,它包含任何源,例如.php、js、html……等等.源已格式化 - 带有空格和/r/n,但 Twig 将其全部呈现在一行中.我尝试了下一个:
{% autoescape false %}{{ 来源 }}{% endautoescape %}
和
{% autoescape false %}{{ 来源|原始 }}{% endautoescape %}
但没有成功.这是 {{ dump(source) }}
的输出:
string '$builder->add('availability', 'choice', array('选择' =>大批('早上' =>'早晨','下午' =>'下午','晚上' =>'晚上',),'多个' =>真的,));'(长度=219)
解决方案
您尝试将您的页面呈现(或查看)为 HTML.HTML 去除所有额外的空格(制表符、空格、换行符).要使用空格保存格式,您需要使用
标签:
{{ 来源|原始 }}In my Twig template comes variable source, which contains whatever source eg. php, js, html ... etc. Source is formatted - with whitespaces and /r/n, but Twig renders it all in one line. I tried next:
{% autoescape false %} {{ source }} {% endautoescape %}
and
{% autoescape false %} {{ source|raw }} {% endautoescape %}
but didn't managed to success. Here is output of
{{ dump(source) }}
:string '$builder->add('availability', 'choice', array( 'choices' => array( 'morning' => 'Morning', 'afternoon' => 'Afternoon', 'evening' => 'Evening', ), 'multiple' => true, ));' (length=219)
解决方案You try to render (or view) your page as HTML. HTML strips all extra whitespaces (tabs, spaces, line feeds). To save your formatting with spaces you need to use
<pre>
tag:<pre> {{ source|raw }} </pre>
这篇关于在 Twig 中禁用格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文