Checking error page context in default.hbs


I am developing a theme which displays separate featured image (from default.hbs) in the header depending upon whether it is home page or post or page etc. I am using ìs helper to detect the context and is working fine.
However there is no context matching with is helper for error.hbs file. I have tried all the contexts mentioned in Ghost Handlebars Theme Helpers: is page. Please help me in identifying this.

Br, Ekansh

It is recommended not to extend the default.hbs layout in your error.hbs template:

Hi Hannah,

My theme is based on starter theme and it is extending default.hbs layout in error.hbs file. Starter/error.hbs at main · TryGhost/Starter · GitHub

I am newbie in ghost ecosystem so please guide me if my understanding is wrong here.

Hmm yeah that is out of date.

General rule is that it’s ok to extend default if you really must in an error-404.hbs that’s just for missing pages, but the generic error.hbs template can be used to serve all kinds of errors, including errors coming from your default.hbs template… so it’s ideal to not extend a template. An example is shown in the docs I linked to and the default template inside of Ghost: Ghost/error.hbs at main · TryGhost/Ghost · GitHub

However, I think you have a point that it might be useful to be able to do {{#is "404"}} if you did want to extend default.hbs in error-404.hbs :thinking:

1 Like

Yes, that is something which would be really handy to maintain a common look and feel on my theme and possible others as well.
Thanks, it answers my question.

Ok, so I found a workaround to fix my case and detect ‘error’ context. It’s not perfect solution as it makes an assumption but until we get {{#is "404"}} it works!

{{! since we are not able to detect error page context, we are checking all the possible contexts and if nothing matches, it is error page}}
{{#is "home, index, post, page, tag, author, paged, private"}}
{{! normal pages}}
        <h1>Error page</h1>