-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
This behavior occurs when applying the following:
- Filter a collection in twig and store the Generator in a variable
- Check the Generator having iterable content by applying the filter
length - Iterate the Generator in a for loop in twig
In some cases there is nothing to iterate over, so by checking the size of the Generator and seeing there is something to iterate over, I render some content previous to the for loop and then iterate the Generator.
However, the Generator is being closed after applying the filter length, rendering the Generator useless after that.
Example:
{% set collection = ['property1', 'property2'] %}
{% set generator = collection|filter(v => v is same as('property1')) %}
{% if generator|length > 0 %}
{% for item in generator %}
{{ item }}
{% endfor %}
{% endif %}
Is this intent?
Metadata
Metadata
Assignees
Labels
No labels