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

Allow support for control blocks in (named) arguments? #987

Open
GuillaumeGomez opened this issue Mar 11, 2024 · 3 comments
Open

Allow support for control blocks in (named) arguments? #987

GuillaumeGomez opened this issue Mar 11, 2024 · 3 comments

Comments

@GuillaumeGomez
Copy link
Collaborator

GuillaumeGomez commented Mar 11, 2024

Currently, we can't pass expressions as arguments to macros (or filters). So code like this doesn't work:

    {%
        call release_macros::header(
            {% if description.is_empty() %}""{% else %}description{% endif %},
            tab=release_type,
            owner={% if let Some(owner) = owner %}owner{% else %}false{% endif %}
        )
    %}

Would you agree to add support for this?

@djc
Copy link
Owner

djc commented Mar 12, 2024

Ugh. Are there workarounds, and how bad are they? Is there precedent for this in other Jinja(-like) engines?

@GuillaumeGomez
Copy link
Collaborator Author

In tera at least, can't find anything mentioned about it in the official jinja package in python though.

And the workaround isn't that ugly, you just declare a variable above instead:

    {% set owner = false %}
    {% if let Some(owner_val) = owner %}
        {% set owner = owner_val %}
    {% endif %}
    {%
        call release_macros::header(
            {% if description.is_empty() %}""{% else %}description{% endif %},
            tab=release_type,
            owner=owner
        )
    %}

@djc
Copy link
Owner

djc commented Mar 12, 2024

Okay, let's keep this open and see if anyone else turns up with similar requirements.

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

No branches or pull requests

2 participants