JohnSG
JohnSG

Reputation: 1667

jekyll - make a list of page.tags

I'm new to jekyll and am working on building my site.

I have a "posts" layout where I'd like to have all the tags associated with the post appear in the left column. The problem I'm running into is that using {{ page.tags }} returns a list of tags that are not comma-separated and looks messy. See here for an example.

The html code for the layout page is:

<div class="span3">
    </br>
    <img src="{{ page.root }}assets/img/glyphicons_045_calendar.png" /> {{ page.date | > date: "%d %B %Y" }}    
    </br> 
    <img src="{{ page.root }}assets/img/glyphicons_066_tags.png" /> {{ page.tags }}
 </div>

<div class="span9">
    <h1> {{ page.title }} </h1>
    {{ content }}
</div>

Any advice on how to (a) get the tags list to be comma-separated and (b) wrap around so it stays within the left column? Thanks!

Upvotes: 8

Views: 5638

Answers (2)

rath
rath

Reputation: 4079

For more precise control over what you can do with tags use the for operator:

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

This example is taken verbatim from somewhere. There are also more control structures to choose from.

Upvotes: 5

Carlos Agarie
Carlos Agarie

Reputation: 4002

You might try to put them inside a <p> tag so they can wrap around.

To have them comma-separated, you can follow the jekyll docs and use:

{{ page.tags | array_to_sentence_string }} => foo, bar, and baz

As is said in the Jekyll wiki.

Upvotes: 10

Related Questions