Loop.hbs and primary_tag

Hi, I have a loop.hbs file in order to list all the post within a tag.

loop.hbs structure is :
{{#foreach posts visibility=“all”}}

{{/foreach}}

How can I do in order to exclude posts with a specific tag (#ads for example)
Thanks,

You can use the #get helper to achieve this:

In your case, it would be (just from top of my mind, without having it tested) the following. The - in front of the tag slug excludes it.

{{#get "posts" filter="tags:-hash-ads"}}
    {{#foreach posts}}
        ...
    {{/foreach}}
{{/get}}

I understand what you mean
But, I’m in {{tag}} context. Read this :

Well, the same principle applies there.

{{#get "posts" filter="tags:[{{tag.slug}},-hash-ads]"}}
    {{#foreach posts}}
        ...
    {{/foreach}}
{{/get}}

I am not on a machine that has Ghost installed, so can’t test this for you, but you get the idea. Within the tag context, get the posts, filter them based on the tag you are currently in and exclude the #ads tag, then loop through them.

Thank you, I’ll try this solution and get back to you.

1 Like