Last active
November 6, 2017 21:30
-
-
Save kevinmpowell/54dcdd616c40130a5f1e3d4fb7d1ec18 to your computer and use it in GitHub Desktop.
Differentiate a string from an array when looping over mixed values in nunjucks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set mixed_object = { | |
key_1: 'Delta', | |
key_2: 'Epsilon', | |
key_3: ['Zeta', 'Eta', 'Theta', 'Iota'] | |
} %} | |
{% for key, value in mixed_objct %} | |
{% if value[0].length > 1 %} | |
{# This is an array, do array stuff with it #} | |
{{ value | join('<br>') | safe }} | |
{% else %} | |
{# This is just a string, array filters will break it, do string stuff with it #} | |
{{ value }} | |
{% endif %} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment