Reputation: 351
I have a template tag which returns datetime objects converted to the user's timezone. To format it, I'd prefer the builtin filter "date" to format it.
Is it possible to use a filter on the result of a template tag?
Upvotes: 3
Views: 1038
Reputation: 101
You can wrap your custom templatetag with 'filter' templatetag:
{% filter date %}
{% your_custom_tag %}
{% endfilter %}
More information here: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#filter
Upvotes: 10
Reputation: 34593
Yes, if course you can. Filters are just functions that can be imported. Import the filter function you need from django.template.defaultfilters and pass your arguments to it.
Upvotes: 0