Repository: rinja-rs/askama (language: rust)

Issue:
Include statement has no effect when used from a block fragment
When using a block fragment include statements don't seem to work.

See https://github.com/OscartGiles/askama/commit/74162b9453486a53a4de40bba905b4be31dcf3f0 for an example. 

Is this intented behaviour or a bug?


Discussion / hints:

Fix patch:
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index decb01cb..7d295240 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -822,6 +822,7 @@ impl<'a> Generator<'a> {
         };
         let locals = MapChain::with_parent(&self.locals);
         let mut child = Self::new(self.input, self.contexts, heritage.as_ref(), locals);
+        child.buf_writable.discard = self.buf_writable.discard;
         let mut size_hint = child.handle(handle_ctx, handle_ctx.nodes, buf, AstLevel::Top)?;
         size_hint += child.write_buf_writable(buf)?;
         self.prepare_ws(i.ws);


Test patch:
diff --git a/testing/templates/fragment-include.html b/testing/templates/fragment-include.html
new file mode 100644
index 00000000..fb7f6f8c
--- /dev/null
+++ b/testing/templates/fragment-include.html
@@ -0,0 +1,9 @@
+{% extends "fragment-base.html" %}
+
+{% block body %}
+{% include "included.html" %}
+{% endblock %}
+
+{% block other_body %}
+<p>Don't render me.</p>
+{% endblock %}
\ No newline at end of file
diff --git a/testing/tests/block_fragments.rs b/testing/tests/block_fragments.rs
index ae723b6d..e5204b08 100644
--- a/testing/tests/block_fragments.rs
+++ b/testing/tests/block_fragments.rs
@@ -103,3 +103,15 @@ fn test_specific_block() {
     let t = RenderInPlace { s1 };
     assert_eq!(t.render().unwrap(), "\nSection: [abc]\n");
 }
+
+#[derive(Template)]
+#[template(path = "fragment-include.html", block = "body")]
+struct FragmentInclude<'a> {
+    s: &'a str,
+}
+
+#[test]
+fn test_fragment_include() {
+    let fragment_include = FragmentInclude { s: "world" };
+    assert_eq!(fragment_include.render().unwrap(), "\nINCLUDED: world\n");
+}