-
|
I have a yaml front matter item that might be a list: foo:
- bar1
- bar2
- bar3or it might be a dictionary: foo:
bar1: baz
bar2: 2
bar3: 3 bazIs there a way to parse |
Beta Was this translation helpful? Give feedback.
Answered by
pdehaan
Jun 29, 2023
Replies: 1 comment
-
|
I couldn't easily figure out how to call 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 %} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
btrem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:USAGE