-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
Setting and updating variables in loop #759
Comments
You could probably use for-else: #518
|
I know about for-else but that is not possible in this case. I loop over all the categories, and inside that loop I go over all the dishes, check the category of each dish AND if dish.category == category_of_loop I output the dish. |
Then you could use a {% set hash_dishes = std::cell::Cell::new(false) %}
{% for dishes in restaurant %}
{% for dish in dishes %}
{% if dish.is_tasty() %}
{% let _ = hash_dishes.set(true) %}
dish
{% endif %}
{% endfor %}
{% endfor %}
{% if !hash_dishes.get() %}
no dishes
{% endif %} |
Thanks a lot! This works perfectly. |
You're welcome! :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a loop which outputs some items. However, if no items are outputted (because there are none) I want to show "no items". Basically I need to be able to set and update variables in Askama.
My code:
The text was updated successfully, but these errors were encountered: