Skip to content

Nunjucks include throws error in for-loop else case #3197

Answered by pdehaan
tombreit asked this question in Q&A
Discussion options

You must be logged in to vote

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:

{% set mylist = [] %}

{% if mylist.length %}
  {% for item in mylist %}
    {% include "testinclude.njk" %}
  {% endfor %}
{% else %}
  {% include "testinclude.njk" %}
{% endif %}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tombreit
Comment options

@pdehaan
Comment options

Answer selected by tombreit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants