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

标签 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..." />

我该怎么办?

谢谢你。

最佳答案

尝试使用 |replace 过滤器。

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

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

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

相关文章:

symfony - 如何制作 symfony2 表单以在表单类型中自动输入当前登录用户的 ID?

php - 从 PHP 和 Timber/Twig 中的高级自定义字段对转发器字段进行排序

css - Symfony Assets 配置

php - 如何在 Twig 中渲染 CSRF 输入?

php - 在 Twig 中显示 token 用户名 symfony2

php - Twig 将内容附加到 block

symfony - 您如何检索Symfony2的当前日期

php - DateTime::createFromFormat(...) 有替代品吗?

javascript - jTable 如何与 Symfony 2 配合使用?

php - 如何通过选中复选框从 Twig 中的表中获取数据