Hello everyone
Setup
On my Grav site, I have a main blog page with articles and subblogs with articles, a structure like this:
/blog
/article-1
/article-2
/subblog-1
/article-3
/subblog-2
/article-4
Each article has one or more tags, and every article of a subblog has at least the same tag as the subblog. Now I’m facing the problem that the taxonomylist plugin displays emtpy tags.
Problem
On my main blog page /blog
, all tags get displayed, with articles, subblogs and those articles. No difficulties here so far. But then on a subblog page like /subblog-1
, it not only displays tags of the articles, but also all other used tags, which aren’t used on the subblog.
Because of that, I get a page looking like this:
As a reference, ‘Tutorials’ is the main blog page and ‘Seiten’ is the subblog, the page visited. Since there are no articles in this subblog with the tag ‘Login’, it displays an empty page. The URL/ Path is
/tutorial/seiten/tag:Login
, which means that it gets only the articles of the tag ‘Logins’ in the subblog ‘Seiten’
possible Solutions
Two possible solutions come into my mind, but I don’t know how to do it or where the problem is that it doesn’t work:
- S1 (Preferred): The plugin only displays the tags used within this subblog. So it is like a combined filtering, since it filters only articles below this subblog in general, and optionally a tag within this subblog.
- S2: On the subblog, all tags of the entire blog page (main blog) get displayed. But when selecting a tag, it displays all articles, not only the ones from the subblog.
What I’ve tried
According to the README of the plugin, I tried including the taxonomylist with this, where I also tested it out with/ without the of_page
and children_only
separately and combined:
{% include 'partials/taxonomylist.html.twig' with {
'base_url':new_base_url,
'taxonomy':'tag',
children_only: true,
of_page: page.parent
} %}
I also tried setting of_page
as a string, with the collection syntax (@), changed it to page.descendants
so it gets only pages below, and some more ideas I had, but none of them solved the issue.
This is the partials/taxonomylist.html.twig
file from the theme:
{% set taxlist = children_only is defined ? taxonomylist.getChildPagesTags(pf_page) : taxonomylist.get() %}
{% if taxlist %}
<span class="tags">
{% for tax,value in taxlist[taxonomy] %}
{% set label_class = uri.param(taxonomy) == tax ? 'label-primary' : 'label-secondary' %}
<a class="label label-rounded {{ label_class }}" href="{{ base_url }}/{{ taxonomy }}{{ config.system.param_sep }}{{ tax }}">{{ tax }}</a>
{% endfor %}
</span>
{% endif %}