我有以下代码:
{% 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&#8217;s so easy to play this game, isn&#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&#8217;s so easy to play this game, isn&#8217;t it? The..." />
我该怎么办?
谢谢你。
最佳答案
尝试使用 |replace
过滤器。
|replace({"\n": "", "\r": "", "\t": ""})
例如
{{ item.description|replace({"\n": "", "\r": "", "\t": ""}) }}
关于twig - 如何从 Twig 中的字符串中删除新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28489991/