djc / askama

Type-safe, compiled Jinja-like templates for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot specify single named argument in macro

kotx opened this issue · comments

Given a simple macro with a single named argument, I cannot call the macro with the named argument explicitly specified.

{% block content %}
{% macro button(label) %}
<button>{{ label }}</button>
{% endmacro %}

{% call button(label="hi") %}
{% endblock %}
error: problems parsing template source at row 5, column 25 near:
       "=\"hi\") %}\n{% endblock %}"

My guess is that this is because named arguments must be last, and the check is erroneously(?) rejecting this syntax.

It works as expected when label= is not specified.

I could be missing something.

Ahh, that's a silly oversight. @GuillaumeGomez want to have a look? (Or @kotx, would be great if you can do a PR. See the relevant code in #910.)

Sending a fix in the next hours.

I just tested with:

#[derive(Template)]
#[template(
    source = r#"{% macro button(label) %}
{{- label -}}
{% endmacro %}

{%- call button(label="hi") -%}
"#,
    ext = "html"
)]
struct OnlyNamedArgument;

#[test]
fn test_only_named_argument() {
    assert_eq!(OnlyNamedArgument.render().unwrap(), "hi");
}

And it works fine. Did I miss something?

@kotx which version of Askama are you using? We merged named arguments recently but I haven't released a version that supports it to crates.io yet, so it's possible the documentation (which gets built from the main branch) is ahead of what's actually supported in a crates.io release.

it's possible the documentation (which gets built from the main branch) is ahead of what's actually supported in a crates.io release.

Oh, I didn't realize it hasn't been released yet. My mistake!

I hate to ask this but any timeframe for when it gets released? I'm okay with directly pulling the main branch as a dependency for now, so thanks either way.