twig中的调用方法,如何避免显示为输出的返回

发布于 2025-01-23 19:26:16 字数 711 浏览 2 评论 0 原文

在策略中正确授权它之后,我正在从树枝模板内部调用一个预先存在的对象中的方法:

{{ thisEmail.AddCC('[email protected]') }}

我的问题是我用来产生副作用的对象方法,而不是返回任何文本, ,这在我的模板输出中留下了可见的“ 1”。

如何删除此输出?我有一个工作:

{{ thisEmail.AddCC('[email protected]')|trim('1') }}

但是我觉得它并不完全优雅,只能消除该特定结果。我宁愿写 | nul | drop 之类的东西,并使过滤器删除所有内容,而不管它以输入的方式收到了多少或什么样的东西。

我知道如何通过编写自己的树枝扩展过滤器来做到这一点,但是我的问题是:有一种很好的方法可以用核心的小树枝语言来实现这一目标,而不是延伸?

I am calling a method in a pre-existing object from inside a Twig template, after properly authorizing it in policy:

{{ thisEmail.AddCC('[email protected]') }}

My problem is that the object method, which I use to produce a side-effect, not to return any text, returns true, and that leaves a visible "1" in my template output.

How to remove this output? I have this one working:

{{ thisEmail.AddCC('[email protected]')|trim('1') }}

But I feel it's not entirely elegant, and it can only remove that specific result. I would prefer to write something like |nul or |drop and have the filter drop everything, regardless of how much or what kind of stuff it receives as input.

I know how to do it by writing my own Twig extension filters, but my question here is: is there a nice way of achieving this with the core Twig language, un-extended?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤痕我心 2025-01-30 19:26:16

如果您想要 twig 语句不要输出任何内容,则可以使用 do 标签,例如

{% do thisEmail.AddCC('[email protected]') %}

source

If you want a twig statement not to output anything you can use the do tag, e.g.

{% do thisEmail.AddCC('[email protected]') %}

source

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文