You can get the variable value by name from the locals()
:
{{locals()['mylist' + str(i)][0]}}
Demo:
>>> from bottle import template
>>> template('{{locals()["list" + str(i)]}}', i=1, list1=[1,2,3,4])
u'[1, 2, 3, 4]'
Personally, I don't like the solution. Better construct a context
dict with mylist1
, mylist2
... mylistn
as keys and actual lists as values and pass it to the template:
>>> template('{{context["list" + str(i)]}}', i=1, context={'list1': [1,2,3,4]})
u'[1, 2, 3, 4]'
Hope that helps.