diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 5921609d4..09c6ce6be 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -2034,7 +2034,7 @@ impl MapChain<'_, &str, LocalMeta> {
let name = normalize_identifier(name);
self.get(&name).map(|meta| match &meta.refs {
Some(expr) => expr.clone(),
- None => name.to_string(),
+ None => format!("&{name}"),
})
}
diff --git a/testing/templates/macro-iter.html.j2 b/testing/templates/macro-iter.html.j2
new file mode 100644
index 000000000..c3726a173
--- /dev/null
+++ b/testing/templates/macro-iter.html.j2
@@ -0,0 +1,16 @@
+{%- macro list(list) -%}
+
+ {%- for item in list %}
+ - {{item}}
+ {%- endfor %}
+
+
+ {%- for item in list %}
+ - {{item}}
+ {%- endfor %}
+
+{%- endmacro -%}
+
+{%- for foo in foos %}
+{% call list(foo.list) %}
+{%- endfor %}
diff --git a/testing/tests/macro.rs b/testing/tests/macro.rs
index 6b0eca5d0..4ae3c1572 100644
--- a/testing/tests/macro.rs
+++ b/testing/tests/macro.rs
@@ -1,4 +1,5 @@
use askama::Template;
+use std::collections::BTreeSet;
#[derive(Template)]
#[template(path = "macro.html")]
@@ -73,3 +74,13 @@ fn str_cmp() {
let t = StrCmpTemplate;
assert_eq!(t.render().unwrap(), "AfooBotherCneitherD");
}
+
+#[derive(Template)]
+#[template(path = "macro-iter.html.j2")]
+struct MacroIterTemplate {
+ foos: Vec,
+}
+
+struct Foo {
+ list: BTreeSet,
+}