Unable to list Jekyll pages by tag
purpose
Create a list of pages filtered by a single tag.
Problem
The list is not displayed.
things i have tried
I started with the <nav>
default element on the Jekyll site:
<nav class="site-nav">
<div class="trigger">
{% for page in site.pages %}
{% if page.title %}
<a class="page-link" href="{{ page.url | prepend: site.baseurl }}">{{ page.title }}</a>
{% endif %}
{% endfor %}
</div>
</nav>
When the Jekyll site is serve
d, it puts the "About" page in the element nav
.
I added two tags to the front table of different pages on the site:
tags:
- eng
---
I tried both formats:
tags: eng
---
-
Try to list through
site.tags.eng
(also triedsite.tags[eng]
andsite.tags["eng"]
):<div class="trigger"> {% for page in site.tags.eng %} {% if page.title %} <a class="page-link" href="{{ page.url | prepend: site.baseurl }}">{{ page.title }}</a> {% endif %} {% endfor %} </div>
-
Try testing the tag (with or without quotes):
<div class="trigger"> {% for tag in site.tags %} {% if tag == "eng" %} {% if page.title %} <a class="page-link" href="{{ page.url | prepend: site.baseurl }}">{{ page.title }}</a> {% endif %} {% endif %} {% endfor %} </div>
-
Also add the list of tags to
_config.yml
:# Tags tags: [eng, jpn]
-
Add a tag to the example post to see if only posts are indexed
other questions I've looked at
- Making a list of pages (not posts) in a given category : not sure if what I'm trying is fundamentally different
- http://jekyllrb.com/docs/variables/ : The main Jekyll documentation does not say that tags should be specified in YAML config
- https://stackoverflow.com/questions/18944264/jekyll-plugin-liquid-tag-creation-not-working : It seems I didn't have to build a whole plugin for this.
source to share
Settings tags on the page:
tags: [ tag1, tag3 ]
---
or
tags:
- tag1
- tag2
---
If you want to create a list from a tag:
<ul>
{% for p in site.pages %}
{% if p.tags contains 'tag2' %}
<li><a href="{{ p.url | prepend: site.baseurl }}">{{ p.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
Secondary responses:
- It is ok to display the page in the page list (default menu), this is the page
- The tagged pages won't show up in the site.tags hash, only posts.
source to share