Custom delineation with single || multi author


#1

Version: 1.22.4

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}}


#2

Hey there :wave:

Can you try this:

{{#has author="count:>1"}}
    {{!-- Multiple authors --}}
    {{#foreach authors}}
        {{#if @first}}
            {{name}}
        {{else if @last}}
            & {{name}}
        {{else}}
            , {{name}}
        {{/if}}
    {{/foreach}}
{{else}}
    {{!-- Single author --}}
    {{author}}
        {{name}}
    {{/author}}
{{/has}}

Hope this helps!


#3

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.


#4

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%.


#5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.