Jekyll Tag List on a Page
Asked Answered
L

2

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!

Louettalough answered 21/5, 2014 at 4:16 Comment(1)
whtas your styling i.e. cssVellicate
S
12

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.

Shaniceshanie answered 21/5, 2014 at 6:18 Comment(1)
Thank you very much for this answer, it works perfectly. They will sing songs about you and your triumphs.Louettalough
K
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>
Kreutzer answered 5/11, 2015 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.