show same image multiple times, depending on the value of a variable

94 views
Skip to first unread message

Gergely Horváth

unread,
Mar 30, 2021, 5:25:19 AM3/30/21
to oTree help & discussion
Hi All,

I would like to show the same image multiple times on the same page. The number of times depends on the value of a variable which is different for each player. I tried to use for loop in the html, but I do not know how to convert the variable's value to an iterable list. Let say i want to show the image 3 times, then I would need a list with 0,1,2 in it. The Html does not convert the value to a list while it seems that I cannot pass lists to the template by the method vars_for_template. 

Any idea how to proceed in this case?
Best,
Gergely 

Chris @ oTree

unread,
Mar 30, 2021, 10:51:18 AM3/30/21
to oTree help & discussion
You can pass lists in vars_for_template like any other value, e.g.:
return dict(my_list=[1,2,3])

Then in the template use a for-loop to display it: {% for item in my_list %} whatever {% endfor %}

Reply all
Reply to author
Forward
0 new messages