Skip to content

Instantly share code, notes, and snippets.

@Wolfr
Last active December 19, 2015 08:29
Show Gist options
  • Select an option

  • Save Wolfr/5926144 to your computer and use it in GitHub Desktop.

Select an option

Save Wolfr/5926144 to your computer and use it in GitHub Desktop.
How to get sub items from an array in Liquid?
JSON:
case studies: [
[ "Nubaru",
["Nubaru Yearly Report", "Web design", "2013", "/case-studies/Nubaru.html", "/images/case-studies/Nubaru.png"]
],
[ "Ekande",
["Ekande application", "Web application design", "2013", "/case-studies/Ekande.html", "/images/case-studies/Ekande.png"]
]
]
Jekyll HTML:
<ul>
{% for items in page.case-studies %}
{% for item in items %}
<li>
{{ item }}
<!-- How to get sub items? -->
</li>
{% endfor %}
{% endfor %}
</ul>
@mislav
Copy link
Copy Markdown

mislav commented Jul 4, 2013

You can access sub-items as you would in a programming language: via square brackets and array indices:

{{ item[0] }}

However, for your use-case it might be more maintanable for each case study to be a hash; then you would iterate an array of hashes. See my fork. I've used YAML syntax but it should allow you to some degree to paste in JSON as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment