Why assign? You can only sort a for loop when it is assigned – so it’s good to get into that practice. If you wanted to sort a for loop by anything other than the exact order you’ve specified, assigning is the way to go.
I’m not sure if that exact code will work on your site, but given a file called designers.yml in a _data folder in the root of your project, it should.
You probably want something like this:
<ul> {% assign designers = site.data.designers %} {% for designer in designers %} <li><a href="{{ designer.src }}" target="_blank">{{ designer.name }}</a></li> <li><a href="{{ designer.src }}" target="_blank">{{ designer.name }}</a></li> <li><a href="{{ designer.src }}" target="_blank">{{ designer.name }}</a></li> {% endfor %} </ul>
Why
assign
? You can only sort a for loop when it is assigned – so it’s good to get into that practice. If you wanted to sort afor
loop by anything other than the exact order you’ve specified, assigning is the way to go.I’m not sure if that exact code will work on your site, but given a file called
designers.yml
in a_data
folder in the root of your project, it should.