在同一个变量上使用两个树枝扩展

Use two twig extensions on the same variable

我需要用 twig 打印 blogPost 的内容(其中包含 HTML 内容),所以我使用了 raw 扩展。

我还必须用另一个替换部分内容,但是如果已经有 raw 扩展名,我如何使用 replace 扩展名?

我试过:

{{ blogPost.getPost()| raw | replace('[[video]]': '(your video here)') }}

{{ {{blogPost.getPost()| raw}} | replace('[[video]]': '(your video here)') }}

{{ blogPost.getPost()| raw, replace('[[video]]': '(your video here)') }}

但其中 none 有效。

replace('[[video]]': '(your video here)')

应该是

replace({'[[video]]': '(your video here)'})

那是因为您需要传递一个数组来替换函数而不是标量值

编辑

试试

{{ blogPost.getPost()|replace({'[[video]]': '(your video here)'})|raw }}