-
I'm not able to call a Nunjucks {% set mylist = [] %}
{% for item in mylist %}
{% include "testinclude.njk" %}
{% else %}
This include fails in else statement:
{% include "testinclude.njk" %}
{% endfor %} If the list is empty, the
Complete error log
Replace the include with a string and everything is fine. Somehow I'm stuck - what am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
pdehaan
Feb 10, 2024
Replies: 1 comment 2 replies
-
I can reproduce it in Eleventy 2.0.1, but you'd have to try it in vanilla Nunjucks and possibly file an upstream bug if it reproduces outside of Eleventy. In the meantime, you can probably use a slightly more verbose {% set mylist = [] %}
{% if mylist.length %}
{% for item in mylist %}
{% include "testinclude.njk" %}
{% endfor %}
{% else %}
{% include "testinclude.njk" %}
{% endif %} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
tombreit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can reproduce it in Eleventy 2.0.1, but you'd have to try it in vanilla Nunjucks and possibly file an upstream bug if it reproduces outside of Eleventy.
In the meantime, you can probably use a slightly more verbose
if..else
to work around it: