Jekyll Tag List on a Page

5.3k Views Asked by At

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!

2

There are 2 best solutions below

1
On BEST ANSWER

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.

0
On

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>