Reputation: 6427
Generate a page list filtered by a single tag.
List doesn't appear.
I started with the <nav>
element in the default 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, this puts an "About" page in the nav
element.
I added two tags to different pages' front matter on the site:
tags:
- eng
---
I tried both formats:
tags: eng
---
Try enumerating through site.tags.eng
(also tried site.tags[eng]
and site.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 for a 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 a tag list to _config.yml
:
# Tags
tags: [eng, jpn]
Add a tag to the sample post to see if only posts are being indexed
Upvotes: 3
Views: 196
Reputation: 52779
Settings tags on a page :
tags: [ tag1, tag3 ]
---
or
tags:
- tag1
- tag2
---
If you want to make 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 answers :
Upvotes: 2