Reputation: 519
I have a json document with some data
{"teams":[{"team":"Team A","evolution":[1,2]},{"team":"Team B","evolution":[3,4]}]}
I try to print it to my view with liquid
{% for team in teams %}
<tr>
<td><a href="#">{{team.team}}</a></td>
<td>{{team.evolution}}</td>
</tr>
{% endfor%}
The html result is
<tr>
<td><a href="#">Team A</a></td>
<td>12</td>
</tr>
<tr>
<td><a href="#">Team B</a></td>
<td>34</td>
</tr>
But what I would like to print is the raw array for the second <td>
<tr>
<td><a href="#">Team A</a></td>
<td>[1,2]</td>
</tr>
<tr>
<td><a href="#">Team B</a></td>
<td>[3,4]</td>
</tr>
Upvotes: 1
Views: 2194
Reputation: 52809
Presuming that you get your datas from a _data/teams.json
file, this works :
{% assign teams = site.data.teams.teams %}
<table>
{% for team in teams %}
<tr>
<td><a href="#">{{team.team}}</a></td>
<td>{{team.evolution | join: "," | prepend: "[" | append: "]"}}</td>
</tr>
{% endfor%}
</table>
Upvotes: 2