-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter in child template replaces other filter in parent template #551
Comments
I think I have a bit of a handle on this. The templates are parsed to this:
Simplifying wildly,
The problem is that both If I modify the VM to flush fn main() {
let mut env = minijinja::Environment::empty();
env.add_test("odd", minijinja::tests::is_odd);
env.add_test("even", minijinja::tests::is_even);
const ONE: &str = "{{ 1 is odd }}";
const TWO: &str = "{% set foo = 1 is even %}{% extends 'one.html' %}";
env.add_template("one.html", ONE).unwrap();
env.add_template("two.html", TWO).unwrap();
let template = env.get_template("one.html").unwrap();
println!("{}", template.render(minijinja::context! {}).unwrap());
let template = env.get_template("two.html").unwrap();
println!("{}", template.render(minijinja::context! {}).unwrap());
} This prints |
Just for obviousness, a const ONE: &str = "{{ 'foobar' | nop }}";
const TWO: &str = "{% extends 'one.html' %}{{ '' | reverse }}"; |
Well spotted. I will apply a slightly modified version of your PR. |
Description
It's probably best to just see the reproduction. As far as I can tell, using
{% set foo = "value" | <filter> %}
in a template that extends another affects filters in the base template.Reproduction steps
Rust minimum working example with
minijinja = "=2.1.1"
inCargo.toml
:This prints "foobar" and "raboof" (!).
It does not matter where the set statement is, so this also produces the same result:
For completeness, Python/Jinja2 3.1.4 minimum working example:
Prints
foobar
andfoobar
as expected.Additional helpful information:
As far as I can see, 0.25.0 works as expected, and 0.26.0 introduced this behaviour.
What did you expect
I'd expect the example to print "foobar" in both cases, as the Python example and version 0.25.0 does.
The text was updated successfully, but these errors were encountered: