Theme won't install - authors issue

Latest or nearly so Ghost, local install and/or Ghost Pro, MySQL 8.

I have a theme that runs fine but won’t install. Here’s the error message:
image
Image text: Fatal error: Replace …/author with …/primary_author or …/authors.[#]

Unfortunately, this is on the author.hbs template. primary_author doesn’t work there. I tried wrapping in the {{#author}} context, but I’ve got some complexity with a match statement with an else, and these playing well together.

gscan bug?

This is my author.hbs code currently (abbreviated):

    {{#get "pages" filter="slug:[{{author.slug}}]" limit=1 as |posts counter|}}
        {{#foreach posts}}
        {{> content width="small"}} 
        {{/foreach}}

    {{#match counter.total "=" 1}}
    {{else}}
{{!-- lots more stuff here not shown --}}
            <section class="author container small">
                {{#if ../author.website}}
                    <h1 class="author-name"><a href="{{../author.website}}" target="_blank" rel="noopener noreferrer">{{../author.name}}</a>
                    </h1>
                {{else}}
                    <h1 class="author-name">{{../author.name}}</h1>
                {{/if}}
                

            {{/match}}
            {{/get}}

        <div class="post-feed container medium" style="margin-top:32px">
            {{#foreach posts}}
                {{> "loop"}}
            {{/foreach}}
        </div>

        {{pagination}}
        

The code above works great, but it won’t pass Ghost’s theme loading check… Argh!

1 Like

what does the “…/” prefix notation mean in Handlebars?

it bumps the context up a level.

This is likely an issue with gscan. Does it match anything here? Issues · TryGhost/gscan · GitHub.

If you moved the problematic bit into a partial, does it avoid the error?

It’s probably a relative of this one: Gscan complains about correct usage of `{{author}}` in context of `default.hbs` · Issue #365 · TryGhost/gscan · GitHub

Except mine’s a fatal error, not just a ‘throw the error and install the theme anyway’ error.

The problem I’m hitting is that I need to do that get to see if there’s a page with the author slug’s slug, and then fall back to showing the author page specified below if not. I can’t close the ‘get’ because I lose the counter variable, but with it open, the {{#author}} context doesn’t work. I fussed around with if vs match vs etc to see if behavior as different, but it wasn’t.

I have settled for the moment for adding a style tag within the #foreach with CSS styling that hides all the author content that the second section writes out. That’s a dumb solution, but it gets the job done.

I was exploring whether there were any other workarounds here.

The only other idea I had was to use the :empty: CSS selector.

<div class="slug-time"></div>

<div class="no-slug-time">
...
</div>
.no-slug-time {
  display: none;
}

.slug-time:empty .no-slug-time {
  display: block;
}

The CSS empty selector requires no children, which includes text and whitespace. That means you’ll likely need to use Handlebars whitespace control.

Thanks, but I think writing out the <style>.no-slug-time {display:none}</style> style right in the theme file is probably easier to execute and maintain than making sure that .slug-time is scrupulously empty. Squashing whitespace in handlebars is a real drag for readability.