在策略中正确授权它之后,我正在从树枝模板内部调用一个预先存在的对象中的方法:
{{ 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?
发布评论
评论(1)
如果您想要
twig
语句不要输出任何内容,则可以使用do
标签,例如source
If you want a
twig
statement not to output anything you can use thedo
tag, e.g.source