Is it possible to list tags for each post in a list?

#1

Im creating a list of featured posts and I want to add the tags associated for each post. Im currently getting a blank render. Ive tried several different ways in the docs but im guessing you can’t use the foreach handler within another foreach loop?

My current code

    {{#get 'posts' limit='18' include='tags' filter='featured:true'}}
        {{#foreach posts}}

            <div class="col-lg-6">
                <li class="post-item-new">
                    <div class="post-image-block-new">
                        <div class="item-post-content-new">
                            <h2 class="post-title_small-new"><a href="{{url}}">{{title}}</a></h2>
                            <div class="item-post-info-new">
                                <div>
<span class="post-date-new"><time class="page-date" datetime="{{date format='YYYY-MM-DD'}}">
                        {{date format="DD MMMM YYYY"}}
                        </time></span></div>
                                <div class="featured-post-tags">
                                {{#foreach tags}}
                                 {{name}}
                                {{/foreach}}
                                </div>
                            </div>
                        </div>
                    </div>
                </li>
            </div>
        {{/foreach}}
    {{/get}}
#2

Your code looks correct (although there’s no need to switch to single quotes for handlebars, ever) - you’ve added tags as an include, and therefore they should appear. Nesting foreach isn’t an issue.

You can also use the {{tags}} helper directly to output a list of tags: https://docs.ghost.org/api/handlebars-themes/helpers/tags/

Do your posts definitely have public tags associated with them?

#3

Ah excellent. That’s my fault.

The Featured posts i was filtering had no tags. I just realized a featured post is different then a featured tag. Added some tags and they rendered as expected.

Thanks!