user10766253
user10766253

Reputation:

Django: How to refer to a variable if a templatetag returns multiple values

How can I access to the variable if a customtemplate tag returns multiple variables?

templatetags.py

def custom_tag(context):
   # do something
   return A, B

and html

{% load templatetags %}
{% custom_tag as A %} # A used as A
{% custom_tag as B %} # B used as B

How can I refer to each variable?

Upvotes: 1

Views: 550

Answers (1)

bruno desthuilliers
bruno desthuilliers

Reputation: 77912

Your tag doesn't "returns multiple variables", it returns one (A, B) tuple, so what you want is:

{% custom_tag as AB %}
<p>AB.0 is '{{ AB.0 }}'</p>
<p>AB.1 is '{{ AB.1 }}'</p>

Upvotes: 8

Related Questions