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

Cannot specify single named argument in macro #923

Closed
kotx opened this issue Dec 5, 2023 · 5 comments · Fixed by #925
Closed

Cannot specify single named argument in macro #923

kotx opened this issue Dec 5, 2023 · 5 comments · Fixed by #925

Comments

@kotx
Copy link

kotx commented Dec 5, 2023

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.

@djc
Copy link
Owner

djc commented Dec 5, 2023

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.)

@GuillaumeGomez
Copy link
Contributor

Sending a fix in the next hours.

@GuillaumeGomez
Copy link
Contributor

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?

@djc
Copy link
Owner

djc commented Dec 5, 2023

@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.

@kotx
Copy link
Author

kotx commented Dec 5, 2023

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.

@kotx kotx closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants