Filter applies before tag?

I was just bitten by surprising behavior, and I want to sanity-check my conclusion, as well as find out where this is documented.

Assuming I’ve implemented a custom simple_tag foo, and a custom filter bar, if I do this:

{% foo arg1|bar %}

The bar filter gets invoked first, and then the foo tag receives the now-modified arg1. (I expected the opposite.)

At first glance I thought this to be surprising as well. I thought there might have been some way to specify the order in which the operations were to be bound. But then I realized the difference. A filter applies to variables. A tag is not a variable.

From the very first paragraph in Filters:

You can modify variables for display by using filters.

It does not say that you can modify tags. The Tags section then goes on to say:

Tags are more complex than variables: Some create text in the output, some control flow by performing loops or logic, and some load external information into the template to be used by later variables.

Since many tags don’t necessarily produce output, I can see where it doesn’t make sense to try and apply filters to them.

1 Like

Interesting. That helps. It also eliminates the majority of use cases I had in mind.

Probably could be clearer in the docs, though. As is, it’s easy to come away with the impression that I got.