Tag page : group posts by private tags

Hi,

I’m working on my tag.hbs template (the tag page) and I’m trying to group my posts by private tags (I’m trying to use public tags as main categories and private tags as subcategories).

The result I would like, for example for the public tag “Food” at the url /tag/food

Tag: Food

Burger (private tag)

Article 1
Article 2
Article 3

Pizza (also a private tag)

Article 4
Article 5
Article 6

I tried to do the following :

        {{#get 'tags'}}
            {{#foreach tags visibility="internal"}}
                <h2>{{ description }}</h2> <!-- a private tag -->
                <div>
                    {{#get "posts" limit="all" include="tags" filter="tags:[{{@root.tag.slug}},{{slug}}]"}}
                    
                        {{#foreach posts}}
                            {{> "card"}} {{!-- partials/card.hbs --}}
                        {{/foreach}}
                    {{/get}}
                </div>
            {{/foreach}}
        {{/get}}

But {{@root.tag.slug}} seems to be empty when I use it inside the get… However if I use it outside (like to print it) it shows well the tag slug.

Would someone have an idea how to solve it ? I searched everywhere but no clue :thinking:

Thanks in advance,

Julien

Nested get-helpers is a bit of a :grimacing: usecase which is likely to affect performance. I personally wouldn’t approach it like this, I think you’d be better off hard-coding it, if it isn’t going to change often - or making clientside requests directly with the Content API.

As a punt/guess: try replacing @root.tag.slug with ../tag.slug

Thank you for your quick reply.

I already tried it :

{{#get "posts" limit="all" include="tags" filter="tags:[{{../tag.slug}},{{slug}}]"}}

but I got this error :

Parse error on line 1: ../tag.slug ^ Expecting 'DOLLAR', 'STAR', 'IDENTIFIER', 'SCRIPT_EXPRESSION', 'INTEGER', 'END', got 'DOT_DOT'

or making clientside requests directly with the Content API.

Yes, but as it’s clientside, it wouldn’t be good for the SEO, would it ?

Oop, I forgot tag.slug is not a thing - it would have to be primary_tag.slug if you want something singular, otherwise you’d have to parse out the array that is tags

Yes, but as it’s clientside, it wouldn’t be good for the SEO, would it ?

usually tag index pages don’t do very will in search engines anyway, so it depends what you want to optimise for.

A middleground is what Buffer do on their blog, which has similar tag filters, is to load the first page of posts serverside, but then load any remaining posts on the different tabs/filters using clientside JS

White section at the bottom here:

Thank you, I’ll have a look !