I've implemented a custom Twig filter that wraps certain character sequences with a span. The span element didn't show up in the front end until I allowed it in the text format for the field in question (via Limit allowed HTML tags...), so it seems that Twig filters are applied before text format filters. For my current use case, it seems like it would make more sense to run Twig filters after text format filters. Assuming I'm understanding this correctly, is there a reason this is the intended behavior? And if so, is there a way to change when Twig filters are applied to a field/format?

  • I do not at all think that these two things are related. So it might be some caching?
    – user72672
    Mar 29, 2018 at 7:01
  • It's definitely not related to caching, and while the two types of text filtering and different, they're clearly related. I've confirmed that the Limit allowed HTML tags filter is applied after the Twig filter. While there are probably circumstances where that's desirable, it would be nice to be able to change the order. Mar 30, 2018 at 21:17

1 Answer 1


I ended up solving this by running the field through the render filter first, then my custom filter. The text format filters are applied at the render stage, so now the custom filter runs after them. The finished order is:

{{ field | render | custom_filter }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.