Handlebars help - #get filters with variable

Hello, I’m struggling a bit with loops using filters.

I’m looping through tags, and then trying to retrieve all posts for a tag (simple enough).
My tags loop works

{{#get "tags" limit="all"}}
  {{#foreach tags as |alltags|}}
  {{/foreach}}
{{/get}}

And I can retrieve {{alltags.slug}} when I do this.

But then if I try to iterate on posts I get no results. (the below does not work)

{{#get "posts" filter="tags:{{alltags.slug}}" limit="3" as |related_posts|}}
   {{#foreach related_posts}}
   <li><a href="{{url}}">{{title}}</a></li>
{{/foreach}}

Note: If I manually enter the slug name (e.g. motorcycles) the code works. But I can’t do the filter on tags using another variable.

Stumped as I’ve seen themes do this. Any ideas??

Thank you

Dana

Can you go back a step and explain what it is you want to achieve?

The variable you create only exists within the loop, so it’s not going to work like that - but also trying to search for all tags makes no sense as that is the default, and doing 2 big queries like that is not great for performance…

I guess there is some other thing you’re trying to achieve - at a guess, maybe this is what you are looking for: Tutorials

Thank you for your consideration! Yes, more detail below — was just trying to be as brief as possible. I’d love to know a smarter way than nested calls. My website isn’t huge (about 10K visitors/month).

I’m trying to restructure my main page. I want to show “sections”. The definition of a section of the site is a tag. For each tag-based section, I want to show a dynamically generated card.

This is a screenshot of what it should look like below. I’m just using Casper post-card elements as the sections. As you can see the posts in these are unfiltered (they’re the same posts in each card), so I’d like to filter them by card.

Secondary thing I’d like to avoid using a #get query for: the “xx posts” part at the bottom.

Figured out the second question with include="count.posts" per docs.

Disregard, I ended up NOT doing my nested queries because it’s too much. The sections were fine with the description and number of posts. Also you’re right, it’s not good for performance.

Thanks anyway!