Hello!
I’ve been trying to create a “selected tag” template. Something like this:
But no matter what I try, I cannot seem to do it. I’ve tried something like this, when I’m on a tag page:
<div class="index-tags">
<span class="index-tag">
<a href="/">All Posts</a>
</span> |
{{#get 'tags' limit='all' as |tags|}}
{{#foreach tags as |my_tag|}}
<span class="index-tag{{#has slug=my_tag.slug}} selected{{/has}}">
<a href="{{ my_tag.url }}">{{ my_tag.name }}</a>
</span>
{{#if @last}}
{{else}}
|
{{/if}}
{{/foreach}}
{{/get}}
</div>
Is it possible to do this? I guess I want to:
- Go through all the tags
- For each tag, compare it to the page I’m in
- If it’s the same, add the
selected
class to it
My {{#has slug=my_tag.slug}}
should work I believe, but because I’m inside the foreach
, it seems that slug
has the value of the current tag even though I’m using my_tag
as the iterator. I believe it should keep the page slug since I’m using the iterator there.
Maybe it’s not possible. Any thoughts?
Thank you!
Jose