TWIG - 删除特定字符后的所有内容 [英] TWIG - Remove Everything After Certain Character

查看:25
本文介绍了TWIG - 删除特定字符后的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Twig 中,我想知道是否可以在某个字符之后不渲染所有内容.例如,如果我有字符串 'Ironman 3 : Marvel' 并且我想去掉分号后的所有内容,这样我的字符串就会变成 'Ironman 3'.我想知道这是否可能?

In Twig, I am wondering if it is possible to not render everything after a certain character. For example, if I had the string 'Ironman 3 : Marvel' and I want to strip everything after the semicolon so my string will become 'Ironman 3'. I am wondering if this is possible?

推荐答案

您应该能够通过 {{ movietitle|split(':')[0] }} 的一些变体来做到这一点

You should be able to do this with some variation of {{ movietitle|split(':')[0] }}

这篇关于TWIG - 删除特定字符后的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆