Casper - show more than one tag?

Nothing crazy, but two to three tags showing would be helpful.

Any recommendations on what to change / configure?

2 Likes

This might help you Can I make the Casper theme show all tags (not just one)? - #9 by aneahgi

Inside a post you can invoke the tags with the use of {{#foreach tags}} {{/ foreach}}

I would first make sure there are tags and then invoke them, for example:

{{#if tags}}
<div class='tags'>
{{#foreach tags}}
<a href="{{url}}" title="{{name}}" class="tag-{{id}}">
{{name}}
</a>
{{/foreach}}
</div>
{{/if}}

Foreach makes the code inside it repeat as many times as there are tags you have and inside we generate an “a” link for each tag, all wrapped in a <div class="tags"></div> that will only be shown if there are tags

Thanks! I’ll give that a shot.

What about for the home page?

Foreach takes care of iterating the posts, simply include {{#get}} in front and add the data of the labels

Example in casper’s index.hbs file:

Before:

<div class="post-feed">
            {{#foreach posts}}

                {{> "post-card"}}

            {{/foreach}}
        </div>

After:

{{#get "posts" include="tags"}}
<div class="post-feed">
    {{#foreach posts}}
        {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
                {{> "post-card"}}
    {{/foreach}}
</div>
{{/get}}

Docs: Ghost Handlebars Theme Helpers: get

Thanks!

That put me on the right track!