如何从树枝中的字符串中删除新行

时间:2015-02-12 23:39:23

标签: twig

我有这段代码:

{% set pageDescription = item.description|length > 197 ? item.description|striptags|trim|slice(0, 197) ~ '...' : item.description %}

我将从item.description中删除新行

例子我有

<meta name="description" content="An easy playing game about the natural numbers. There will randomly appear the natural. You have to choose what the right after number is. It&amp;#8217;s so easy to play this game, isn&amp;#8217;t it?

The..." />

更改为

<meta name="description" content="An easy playing game about the natural numbers. There will randomly appear the natural. You have to choose what the right after number is. It&amp;#8217;s so easy to play this game, isn&amp;#8217;t it? The..." />

我该怎么做?

谢谢。

2 个答案:

答案 0 :(得分:10)

试试

|replace({"\n": "", "\r\n": "", "\t": "", "\n\r": ""})

答案 1 :(得分:2)

如果您只需要html标记,则spaceless {% spaceless %} ... {% endspaceless %}就足够了