'How to use more than one variable in single jinja2 statement
My template is passed a complex object variable from backend. Its structure is :
[ { key_1: [a,b,c, ...], key_2: [d,e,f, ...], key_3: [g,h,i, ...] }, ... ]
In plain english, its a list of dictionaries. And dictionary keys are strings while values are lists themselves.
I want to access 'h but in a generic form. In javascript and in html. But i think the way to access it will be same in both.
This outer list is named outerList and its length is stored in a variable called outerListLength. The dictionary key whose item i want to access is dictKey. The index of the inner list i want to fetch is named innerListCurrentIndex.
One more thing, I dont want to just access any index of the outer loop. I want to specifically access the item in the last index of outer list (and hence the use of length variable in the below code).
What i have right now is :
newValue = {{ outerList [ outerListLength - 1 ]["dictKey"][innerListCurrentIndex]}};
But this above statement is not working and giving me
jinja2.exceptions.UndefinedError: list object has no element -1
TIA
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
