7

I'm attempting to display a list of tags using Jekyll. Here is what my HTML on the page looks like:

<ul>
  {% for tags in page.tags %}
    <li>{{ tags }}</li>
  {% endfor %}
</ul>

And this is the information in my front matter:

---
layout: template
title: Title
tags: all portfolio something
---

I am getting an output, but it is just creating a list like this:

  • all portfolio something

instead of what I am trying to acheive, which is this:

  • all
  • portfolio
  • something

Any troubleshooting on this would be much appreciated, thank you!

IronSummitMedia
  • 262
  • 1
  • 3
  • 10

2 Answers2

11

I tried on a new Jekyll website (with Jekyll 2.0.3), and the following front matter worked well (make sure to use tags, not tag:

---
layout: template
title: Title
tags: all portfolio something
---

You can also use a list:

---
layout: template
title: Title
tags:
- all
- portfolio
- something
---

Then, use in your post or in your layout:

<ul>
  {% for tags in page.tags %}
    <li>{{ tags }}</li>
  {% endfor %}
</ul>

If you still have a problem, consider upgrading Jekyll, providing a MWE or the output HTML/CSS.

Sylvain
  • 2,621
  • 1
  • 15
  • 17
1

For this front matter:

---
layout: template
title: Title
tags: all portfolio something
---

You can assign page.tags | split:&nbsp; into a variable to use for a for loop iteration:

{% assign tags = page.tags | split:&nbsp; %}
<ul>
    {% for tag in tags %}
    <li>{{ tag }}</li>
    {% endfor %}
</ul>

It will output something like this:

<ul>
  <li>all</li>
  <li>portfolio</li>
  <li>something</li>
</ul>
5ervant
  • 3,928
  • 6
  • 34
  • 63