开发者

\t characters in twig output

开发者 https://www.devze.com 2023-04-05 09:55 出处:网络
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=\'\'> .

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号