I’ve got a tuple of values I’m iterating in a Django template (1.4). Some of the values are strings which must just print out, others are tuples containing strings, which must be iterated themselves to print out their values. Is there a way, within the template, that I can decide if a given value, as I iterate over the master tuple, is a string or a list (tuple) ?
Share
There’s no builtin way to do so. A (somewhat dirty IMHO) workaround would be to implement a custom "is_string" filter, but the best solution would be to preprocess the values in the view to make it an uniform list of tuples (or list).
for the filter solution:
and then in your templates:
cf the excellent Django doc for more on custom filters and templatetags:
https://docs.djangoproject.com/en/stable/howto/custom-template-tags/