We’ve got a third-party Django template tag like this:
{% frobnicate "foo", "bar", "baz" %}
do stuff with {{ frobnicator }}
{% endfrobnicate %}
Unfortunately, the do stuff with {{ frobnicator }} part is repeated every time we use the {% frobnicate %} tag.
What’s the easiest way to build a tag so that something like
{% frobnicate2 "foo", "bar", "baz" %}
…expands into the first example?
Update: Simple inclusion tags aren’t enough. I didn’t make it clear in the example above, but I need to be able to manipulate the parameters passed to the expansion.
Create a template filter that will render your custom string instead of a template file.
Declare it like this (this code is tested):
Don’t forget to replace “my-third-party-frobnicator-lib” with a name of an actual third party library that you’re loading.
Then you can render the whole whird-party tag sequence using
{% frobnicate2 "foo", "bar", "baz" %}just as you wanted.