anyone knows how to make twig stop outputting \t and \n characters? my output looks like this:
<ul>\n \t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t<a href=''> ...
for this template:
开发者_StackOverflow社区 <ul>
{% for datum in this.data %}
<li><a href='#'>link</a></li>
{% endfor %}
</ul>
thanks!
That's right, as it says in the Twig manual for whitespaces:
Whitespace is not further modified by the template engine, so each whitespace (spaces, tabs, newlines etc.) is returned unchanged.
You can use the spaceless
-tag to suppress whitespaces.
{% spaceless %}
<div>
<strong>foo</strong>
</div>
{% endspaceless %}
{# output will be <div><strong>foo</strong></div> #}
Have a look at the manual for further options.
精彩评论