djc / askama

Type-safe, compiled Jinja-like templates for Rust
Apache License 2.0
3.25k stars 213 forks source link

Unnecessary fields required when using blocks for partial rendering #1052

Open Tortoaster opened 2 months ago

Tortoaster commented 2 months ago

Given a template like this:

templates/base.html

{% block empty %}
{% endblock %}

{% if let Some(var) = var %}
{{ var }}
{% endif %}

The following code:

#[derive(Template)]
#[template(path = "base.html", block = "empty")]
struct Empty {}

Gives an error:

no field `var` on type `&Empty`

Due to the (empty) match statement generated by the derive macro, even though the field var is not necessary to render just the empty block.

GuillaumeGomez commented 2 months ago

Normally it was fixed in https://github.com/djc/askama/pull/1029. Please try with the main branch to confirm it was fixed.

Tortoaster commented 2 months ago

I'm afraid the issue is still there, I tested it on main (c1366e0).

GuillaumeGomez commented 2 months ago

Ok! Gonna take a look in the next hours.