Display a list of links as [1][2][3] etc

So, I’m creating a list on a page that is basically posts of 100% front matter since there is no content needed. What I’m stuck on now is links. In the front matter, I have a list of links and I want them displayed as [1][2][3] (or however many there are)

It looks like this

---
layout: post
title: lorem ipsum
date: 2016-06-13
tags: ex1 ex2 ex3
sources: https://example.com https://example2.com
---

I thought that I could parse the links the same as I do tags, but that does not work at all and I can’t seem to figure out why. I haven’t even started on actually getting them to display as incrementing numbers because I can’t even figure out this. I can get them to display but the hyperlink is just a combo of all the links instead of each link going to its own site.

{% for source in page.sources %}
{% capture source_name%}{{ source}}{% endcapture %}
<a href="{{ source_name }}"><nobr>{{ source_name }}</nobr>&nbsp;</a>
{% endfor %}

This was my code for displaying tags but it’s completely useless for the sources (and obviously lacks the displaying as numbers part since I have no idea how to do that for jekyll)

You’re close but you need to format the sources YAML as an array so you can loop over them. The way you have it now is a string.

sources: [https://example.com, http://example2.com]

or

sources:
  - https://example.com
  - http://example2.com

To spit out [1] [2] etc you can forloop.index. Check out Liquid’s documentation for some other handy things you can do with for loops.

{% for source in page.sources %}
  <a href="{{ source }}"><nobr>{{ forloop.index }}</nobr>&nbsp;</a>
{% endfor %}
2 Likes

Geez, arrays, why didn’t I think of that. I actually did try subcollections but that worked about half as good as my original attempt.

Thanks for the documentation. I’ve been reading through jekyll documentations and cheatsheets all day trying to find help but I haven’t looked at anything for liquid