Skip to content
Discussion options

You must be logged in to vote

I couldn't easily figure out how to call Array.isArray(), but I was able to do it with a custom filter and a slightly verbose {% if %}...{% else %}...{% endif %} block:

eleventyConfig.addFilter("isArray", Array.isArray);

USAGE

---
title: Bleep bloop
foo2:
  - bar1
  - bar2
  - bar3

foo:
  bar1: baz
  bar2: 2
  bar3: 3 baz
---

{% if foo | isArray %}
  {% for item in foo %}
    - {{ item }}
  {% endfor %}
{% else %}
  {% for item, value in foo %}
    - {{ item }}; {{ value }}
  {% endfor %}
{% endif %}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by btrem
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