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?
1 Answer
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 }}
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.