-
Notifications
You must be signed in to change notification settings - Fork 640
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
Skip items loop #1216
Comments
As I understood you want to loop through the loop and print data if a condition is met. If not matches found print another text. It can be done with a proper logic with the available functions. {% set retailer_title = 'Super Offer' %}
{% set no_matches = true %}
{% for item in data.products_data %}
{% if item.retailer == retailer_title %}
{% set no_matches = false %}
<h3>{{ item.retailer }}</h3>
<p>{{ item.description }}</p>
{% endif %}
{% endfor %}
{% if no_matches %}
There is no offer of {{ retailer_title }} available.
{% endif %} |
@rludgero This is not yet possible with the syntax you provided. The ticket to add loop filtering is #261 and the tracking ticket for nunjucks v4 (which would include this feature) is #1059. Unfortunately, you'll need to use the workaround @lasithds provided above. I am actively working on adding this feature though. Closing as a duplicate. I am waiting on feedback to #1059 (comment), if you have any thoughts on it that would be very helpful. |
Hi @lasithds , this is what I wanted 😉 , it has worked great, thank you very much 👏 . |
Hello everyone,
I'm trying to filter the loop, through the value of the property, but from what I see in nunjucks this option does not exist, or so I think.
As in nunjucks it is not possible to use break or continue in a loop, how i can filter the sequence during iteration, skipping the items?
Is possible to do it, if so, how can I implement it?
Is there a filter?
This is the sample code:
Thanks in advance.
The text was updated successfully, but these errors were encountered: