Writing template tags isn't easy in Django and involves lots of boilerplate code. What is the least painful way to do it?
- Are there any libs for that?
- Are there any tricks that doesn't involve third-party apps?
- What is your way to do it?
(I will make this post a community wiki once I figure how to do it.)
There are some libs for that:
django-templatetag-sugar
Used it before. Makes everythings simpler, but I couldn't figure how to handle lots of optional arguments with it.
Usage example::
django-tagcon, abandoned by original author
django-ttag, fork of django-tagcon
These two look promising because of class-based approach and keyword arguments support (like
{% output limit=some_limit|default:1 offset=profile.offset %}
)Example usage::