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

Tuple unpacking in {% with %} tag. #65

Closed
alexkingnz opened this issue Jun 7, 2022 · 1 comment · Fixed by #66
Closed

Tuple unpacking in {% with %} tag. #65

alexkingnz opened this issue Jun 7, 2022 · 1 comment · Fixed by #66

Comments

@alexkingnz
Copy link

alexkingnz commented Jun 7, 2022

In my data, I have a list of tuples.
I can use them in a for loop:

{% for (v1, v2) in mylist %}
{{ v1 }}: {{ v2 }}
{% endfor %}

However, I only need the first one in the list. I'd like to do:

{% with (v1, v2) = mylist|first() %}
This is the {{ v2 }}
{% endwith %}

(also, I would normally use {% set .... %} in jinja2, but it is missing. Not really a problem if {% with %} can do what I need.)

@alexkingnz
Copy link
Author

So I can solve my problem with:

{% with t = mylist|first() %}
This is the {{ t[1] }}
{% endwith %}

However, tuple unpacking would make it cleaner IMO.

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.

1 participant