-
In my application I have a struct that is Is there built-in syntax or a built-in function that can provide a reference to the overall context like this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
May be you are looking for add_global. Here is how I used it. |
Beta Was this translation helpful? Give feedback.
-
There is some risk with this behavior because it makes that you have a self-referential data structure if you are not careful. In pure theory it would be possible to write a What I would do instead is to say that you wrap the context that you pass for rendering with a helper that makes it self-referential within reason (eg: In short, you would need to change |
Beta Was this translation helpful? Give feedback.
There is some risk with this behavior because it makes that you have a self-referential data structure if you are not careful. In pure theory it would be possible to write a
globals()
function (if an API was added to enumerate all variables in MiniJinja) that returns all variables, but even then you end up with the situation that actual globals are included that you probably don't want such asrange()
,debug()
or that hypotheticalglobals()
function.What I would do instead is to say that you wrap the context that you pass for rendering with a helper that makes it self-referential within reason (eg:
CONTEXT.name
is possible, butCONTEXT.CONTEXT.name
would fail). I added a simple example h…