Skip to content

How to Use Ghost Author Context

By Ahmad Ajmi

Ghost’s author context lets a theme show author data. This post explains which template Ghost chooses, with examples.

Each Ghost author has a page with their name, photo, and posts. Visiting an address such as /author/ahmad puts you in the author context.

The index.hbs theme file is used as the default author context template.

So, how can we know if we’re on the blog home page or the author page? We can use the {{#is 'author'}}{{/is}} helper to know that.

So, in the index.hbs file, we can do.

{{#is 'author'}}

{{/is}}

Between these two lines, we can show the author’s information, like name and photo. But first, we need to use the {{#author}}{{/author}} block helper. Within that helper, we can access the author properties we need.

{{#is 'author'}}
  {{#author}}
    {{ name }}
    <img src='{{ profile_image }}' alt='{{ name }}'>
  {{/author}}
{{/is}}

You might say that you don’t want to use the index.hbs file for the author page. Is there another solution? Yes, we can create a new template file and call it author.hbs.

How does Ghost choose between index.hbs and author.hbs? Well, Ghost will look for the author.hbs first and select it if it exists. If not, Ghost will choose index.hbs. That’s why the index.hbs file is necessary for any Ghost theme.

So, in the author.hbs file, the previous example will be.

{{#author}}
  {{ name }}
  <img src='{{ profile_image }}' alt='{{ name }}'>
{{/author}}

Note that I removed the {{#is 'author'}}{{/is}} helper as we are now in a dedicated author context page.

You can use more than name and profile_image. See the full list at Author object attributes.

Suppose you want to go deeper and create a dedicated page for a single author. For example, if you want to design a unique page for every author. You can name the template file as author-:slug.hbs where the :slug part will be the author slug. So, if your user URL is /author/ahmad/, create the author-ahmad.hbs file.

Ghost checks for the slug-specific author template first. If it is absent, Ghost checks for author.hbs. If both are absent, it uses index.hbs.

That’s all that I wanted to share today, and I hope you find this post helpful.

More from the Blog

Latest Ghost Themes