gpt4 book ai didi

twig - 如何从 Twig 中的字符串中删除新行

转载 作者:行者123 更新时间:2023-12-04 17:09:00 30 4
gpt4 key购买 nike

我有以下代码:

{% 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..." />

我该怎么办?

谢谢你。

最佳答案

尝试使用 |replace 过滤器。

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

例如
{{ item.description|replace({"\n": "", "\r": "", "\t": ""}) }}

关于twig - 如何从 Twig 中的字符串中删除新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28489991/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com