Tags helper - usage

I am trying to use : separator=" • " or other separators to list tags in an article header. I have tried and been unsuccessful with various methods. My code is below.

Any hints appreciated.

<div class="featured-article">
{{#if primary_tag}}
<a href="{{primary_tag.url}}" class="featured-article-tag">{{primary_tag.name}}</a>
{{#if tags}}
{{#foreach tags separator=" &bull; " limit="1" from="2"}}
<span>
<a href="{{url}}" title="{{name}}" class="featured-article-tag">{{name}}</a>
 </span>
 {{/foreach}}
 {{/if}}
 {{/if}}
 </div>

Also, in the below from documentation advanced example, why do i need : {{id}} {{slug}} ?

<a href="{{url}}" title="{{name}}" class="tag tag-{{id}} {{slug}}">{{name}}</a>

The separator parameter is not part of the foreach helper, rather it’s part of the tags helper

So you either need to use the tags helper to output the tags, or if you don’t like its output, use the foreach helper in combination with the @last property to create a structure you like

Hope this helps!

Thanks for this. I tried as per your recommendations and moved the helper at the tag level, but still could not make it work.

I have used the below code that is serving my purpose.

<p class="m-featured-article__tag">
{{#if primary_tag}}
<a href="{{primary_tag.url}}" >{{primary_tag.name}}</a>
{{#if tags}}
{{#foreach tags limit="1" from="2"}}
 <span>&bull;</span>
 <span>
 <a href="{{url}}" title="{{name}}">{{name}}</a>
  </span>
 {{/foreach}}
{{/if}}
{{/if}}
</p>

Hey, the Ghost docs displays a few examples of how to use tags with the separator option: https://ghost.org/docs/api/v2/handlebars-themes/helpers/tags/#example-code

Hi David,
Thanks, the documentation is helpful and i am getting up to speed with using the handelbars syntax.

1 Like