Skip to content
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

Fix include statements within block fragments #1093

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions askama_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions testing/templates/fragment-include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "fragment-base.html" %}

{% block body %}
{% include "included.html" %}
{% endblock %}

{% block other_body %}
<p>Don't render me.</p>
{% endblock %}
12 changes: 12 additions & 0 deletions testing/tests/block_fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Loading