What’s the best way to do custom delineation in Ghost {{authors}}? We want to have the following:
By: Author One
By: Author One & Author Two
By: Author One, Author Two & Author Three
I’d assume that within an {{authors}} block you could find out if there’s only a single author by:
{{#has author=“count:1”}}
{{name}}
{{else}}
{{#foreach authors}}
{{#if@first}}
{{name}}
{{else if @last}}
& {{name}}
{{else}}
, {{name}}
{{/if}}
{{/foreach}}
{{/has}}
However, nothing renders if there’s a single author. Any ideas?
My not ideal solution that works:
{{#if author}}
{{name}}
{{/if}}
{{#if authors}}
{{#foreach authors}}
{{#if@first}}
{{name}}
{{else if @last}}
& {{name}}
{{else}}
, {{name}}
{{/if}}
{{/foreach}}
{{/if}}
That’s basically the inverse of what I initially tried which didn’t work.
Is there a way to, within the {{#foreach authors}} loop to see if index === authors.length or other more dynamic queries? Because then you can do interesting things.
Well, you were saying that nothing renders if there’s a single author, so I showed to the code how it’s used in our Casper theme (we use partials) where it works 100%.