You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding a function with add_function that accepts a &minijinja::State, the context provided at the "global" scope (with the context! macro) doesn't get passed in when within a macro's {% call %} block.
fnjinja_myfunc(state:&minijinja::State) -> String{let global = state.lookup("my_global");match global {Some(_) => "global exists".to_owned(),None => "global DOES NOT exist".to_owned(),}}
Now, rendering main with context! { var_a => "v_a", my_global => "my_global" } currently produces the following output:
global exists
<wrapper>
v_a
global DOES NOT exist
</wrapper>
<wrapper>
v_a
global exists
</wrapper>
The function myfunc expects the variable my_global to be in the current global state. Normally it exists "passively" as shown by the first global exists at the top. However, when entering the macro scope wrapper, the my_global variable is forgotten about even though the function requires looking it (as shown by the global DOES NOT exist).
The third <wrapper> shows my current workaround, where I can "lift" the variables I know my function needs into the current macro scope so the function runs properly.
Additional helpful information:
Version of minijinja: 2.0.3
Version of rustc: rustc 1.76.0 (07dca489a 2024-02-04)
Operating system and version: Fedora Linux 40.20240703.0 (Silverblue)
What did you expect
Variables passed in when rendering a template (with the render function and context! macro), should always be visible in minijinja state. The state should not be forgotten about when entering into a macro call.
The text was updated successfully, but these errors were encountered:
Description
When adding a function with
add_function
that accepts a&minijinja::State
, the context provided at the "global" scope (with thecontext!
macro) doesn't get passed in when within a macro's{% call %}
block.Reproduction steps
A reproduction repo can be found here.
Consider the following custom function
myfunc
And template
main
Now, rendering
main
withcontext! { var_a => "v_a", my_global => "my_global" }
currently produces the following output:The function
myfunc
expects the variablemy_global
to be in the current global state. Normally it exists "passively" as shown by the firstglobal exists
at the top. However, when entering the macro scopewrapper
, themy_global
variable is forgotten about even though the function requires looking it (as shown by theglobal DOES NOT exist
).The third
<wrapper>
shows my current workaround, where I can "lift" the variables I know my function needs into the current macro scope so the function runs properly.Additional helpful information:
2.0.3
rustc 1.76.0 (07dca489a 2024-02-04)
Fedora Linux 40.20240703.0 (Silverblue)
What did you expect
Variables passed in when rendering a template (with the
render
function andcontext!
macro), should always be visible in minijinja state. The state should not be forgotten about when entering into a macro call.The text was updated successfully, but these errors were encountered: