Closed gintsgints closed 1 month ago
https://github.com/gintsgints/handlebars-rust/blob/master/tests/each.rs:
extern crate handlebars; #[macro_use] extern crate serde_json; use handlebars::Handlebars; #[test] fn test_subexpression() { let hbs = Handlebars::new(); let data = json!({"a": 1, "b": [{"n" : "n1"}, {"n": "n2"}]}); assert_eq!( hbs.render_template("{{a}} {{#each b as |ar|}}{{a}}{{ar.n}} {{/each}}", &data) .unwrap(), "1 1n1 1n2 " ); }
Why this test fails with rendering "1 n1 n2" instead? Should not {{a}} be recognized inside each block?
Sorry, I found a solution. I had to use {{../a}} for outer context.
{{../a}}
https://github.com/gintsgints/handlebars-rust/blob/master/tests/each.rs:
Why this test fails with rendering "1 n1 n2" instead? Should not {{a}} be recognized inside each block?