My Jinja top-level context has variables defined in sequence like foo_0
, foo_1
, etc.
I'd like to be able to access those variables dynamically by generating strings with code like "foo_" + str(0)
.
If effect, I want to do something like {{ eval("foo_0") }}
in my Jinja template, and access those variables in sequence.
Is this possible?
Note: I'm using a cloud service I don't control (which provides Jinja templating), so:
- I can't use data structures in the Jinja context (all variable values must be strings).
- I can't customize the Jinja runtime environment or add filters. But it would be helpful to know if this can be solved by adding a custom filter.
contextfunction
decorator, this would be simple! – Olly F-G