Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

children_only being set to true doesn't honor base_url but only gets tags of children of page TWIG code is in #38

Open
fseesink opened this issue Oct 30, 2021 · 3 comments

Comments

@fseesink
Copy link

It is very possible I misunderstand the intention and that this is by design, but it seems like the children_only setting is not taking into account the base_url setting. Instead, it is only taking tags from the children pages of the page where this code is being loaded.

As an example, I am using Grav with Gantry5's Helium theme and was trying to create a sidebar on both the blog_list as well as individual blog_item pages that would list the popular tags from all the blog posts (but only those pages and not all the pages on the site). So I thought that by using code such as the following, this would be achieved:

<h4>Popular Tags</h4>
<table>
  <tr>
    <td>
{% include 'partials/taxonomylist.html.twig' with {base_url: '/blog', taxonomy: 'tag', children_only: true} %}
    </td>
  </tr>
</table>
<p class="nomarginbottom"></p>

Now this works perfectly on the blog_list page that is at /blog. But the moment you load any blog_item pages, this code loads up an empty list. This makes sense if it is assuming children of the blog_item page, but that seems contrary to the idea. I would think the 2 parameters define what pages the plugin checks for tags. But again, it could be I misunderstand this.

Is this the actual design? And if so, is there a way to achieve what I am trying to do? Because I don't see a way to do so.

@fseesink
Copy link
Author

fseesink commented Nov 4, 2021

To be clear, if I do NOT put in children_only: true then the taxonomy list includes tags from ALL pages on the site, even those outside of /blog. Re-reading the docs I see that it says (see bold/italized lines):


...

Simple Include

The plugin provides a Twig template that you need to include in your theme. Something like:

{% include 'partials/taxonomylist.html.twig' with {base_url: my_url, taxonomy: 'tag'} %}

Where my_url is the URL to link to where the collection can be filtered (e.g. /blog) and the taxonomy points to a specific taxonomy type to display (e.g. tag). This will display all tags throughout your site

Child-only Include

You can also include pass an optional parameter that will show taxonomy for child-pages only:

{% include 'partials/taxonomylist.html.twig' with {base_url: my_url, taxonomy: 'tag', children_only: true} %}

...


So the first bolded line seems to indicate that doing so--displaying all tags throughout the site--IS the intended behavior if you do NOT specify/set children_only: true. But what is not clear is whether setting that should limit the tags to just those from pages under the base_url (which to me seemed logical) or those only from pages below the specific page in which the TWIG code runs. The latter I find strange, as what would be the purpose?

@flow7
Copy link

flow7 commented Feb 15, 2023

I have the exact same problem - it seems I can't meaningfully combine the two factors, right?

Following scenario:

  • Blog A
    • Item A.1
    • ...
    • ..
  • Blog B
    • Item B.1
    • ...

Desired outcome:

  • I would like to display in the sidebar of Blog A all tags of the Blog A items, but not blog B tags.
    • Sidebar of Item A1 displays tags of Blog A and all its items.
  • Same as above for Blog B. Blog B displays only Blog B and children tags - the same is true for all its sub-items, eg. Item B1

Any suggestions on how to set this up?

@pmoreno-rodriguez
Copy link

Hi @flow7
In your scenario, in sidebar you have to write this code:

	{# Taxonomy list (if taxonomylist plugin is enabled) #}
		{% include 'partials/sidebar/taxonomylist.html.twig' 
		with {'base_url':new_base_url, 'taxonomy':'tag', children_only: true} %}

And in your taxonomylist.html.twig this:

{% set taxlist = children_only is defined ? taxonomylist.getChildPagesTags() : taxonomylist.get() %}
{# If there is a taxonomy, load taxonomylist.html.twig #}
{% if taxlist and page.template == 'blog' %}
<section>
    <header>
        <h2>Popular Tags</h2>
    </header>
    <ul class="actions">
        {% for tax,value in taxlist[taxonomy] %}
            {% set label_class = uri.param(taxonomy) == tax ? 'secondary' : 'primary' %}
            <li>
                <a class="button small secondary {{ label_class }}" href="{{ base_url }}/{{ taxonomy }}{{ config.system.param_sep }}{{ tax }}">{{ tax }}</a>
            </li>
        {% endfor %}
    </ul>
</section>
{% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants