diff options
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 2 | ||||
-rw-r--r-- | testing/tests/vars.rs | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index b0630df..8f2866e 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -1116,7 +1116,7 @@ impl<'a> Generator<'a> { } fn visit_var(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { - if self.locals.contains(s) { + if self.locals.contains(s) || s == "self" { buf.write(s); } else { buf.write("self."); diff --git a/testing/tests/vars.rs b/testing/tests/vars.rs index 04f9ff2..da8aef6 100644 --- a/testing/tests/vars.rs +++ b/testing/tests/vars.rs @@ -43,3 +43,17 @@ fn test_let_decl() { }; assert_eq!(t.render().unwrap(), "bar"); } + +#[derive(Template)] +#[template( + source = "{% for v in self.0 %}{{ v }}{% endfor %}", + ext = "txt", + print = "code" +)] +struct SelfIterTemplate(Vec<usize>); + +#[test] +fn test_self_iter() { + let t = SelfIterTemplate(vec![1, 2, 3]); + assert_eq!(t.render().unwrap(), "123"); +} |