For the (R)evolution conference site this year I’m using Mixture‘s models to manage our speaker data. As information about speakers is used across the site in multiple places and can change fairly often it makes sense to have it in one place. To do this I have json file containing data about each speaker as follows:

"organisations": [
  [
    {
      "name": "Headscape",
      "url": "http://www.headscape.co.uk"
    },
    {
      "name": "Boagworld",
      "url": "http://www.boagworld.co.uk"
    }
  ]
]

Each speaker will be a member of one or more organisations, each with a name and url. This is stored in a two-dimensional array called ‘organisations’, each entry in an organisation is a name:value pair. To access this data I need to loop through the list of organisations and then loop again through each organisation. I can then output the name and url as a link inside a list item.

{% for org in speaker.organisations %}
  {% for value in org %}
    <li><a href="{{ org[forloop.index0].url }}">{{ org[forloop.index0].name }}</a></li><
  {% endfor %}
{% endfor %}

Working out how to loop within a loop using Liquid was a bit of a struggle as you can’t really write traditional loop, as you can’t do mathematical operations on a variable. I couldn’t find many articles or tutorials online that helped me out, so I guessed it and it seems to work.

And the output:

<li><a href="http://www.headscape.co.uk">Headscape</a></li>
<li><a href="http://www.boagworld.co.uk">Boagworld</a></li>

I’m not a developer. ‘Proper’ development doesn’t come naturally to me so any coding I do tends to be as a result of Googling for pre-existing solutions and then adapting them for my own needs. I couldn’t find any working examples of dealing with multidimensional arrays using Liquid, so I put this together via various tutorials, documentation and plenty of stabs-in-the-dark. If it helps you (or you know a better way) it would be really cool if you couldĀ let me know.