-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't reuse a template file as a layout file #161
Labels
Comments
ErisDS
added a commit
to TryGhost/Ghost
that referenced
this issue
Sep 6, 2019
fixes #10990 - Changed the static router to throw a 400 error for a missing template file, rather than falling back to using the default.hbs file - Falling back is weird and hard to understand, but throwing an error makes it clear that the user has to provide the matching template - The new error reads 'Missing template [filename].hbs for route "[route]".' Assume you have a route.yaml file something like: ``` routes: /: home ``` - In Ghost v2, if you don't have a home.hbs template, Ghost falls back to using the default.hbs file if it's available - Most themes have a default.hbs, however this file is a layout file, depended on by other templates, not a template file itself - In production mode, using the default.hbs as a template causes weird, intermittent layout issues depending on which order pages are loaded - This is due to this issue: TryGhost/express-hbs#161 - In Ghost v3, we will throw a 400 error for missing template files instead of having a fallback - In the example above, navigating to '/' would throw the error 'Missing template home.hbs for route "/".'
New ref: https://forum.ghost.org/t/published-pages-result-in-500-error/13331 This has come up twice recently 🤔 |
Including the full (obscure) error that Ghost sees when this happens:
|
ErisDS
added a commit
to ErisDS/Ghost
that referenced
this issue
Nov 21, 2022
refs: TryGhost/Product#2289 refs: TryGhost/express-hbs#161 - Themes that resuse layouts as templates trigger horrible errors, which are thrown as 500s - But there's nothing the server is doing wrong, it's a theme user, so we downgrade these to 400s - There is more to do here to improve the errors shown, but this is just a first step to ensure that theme issues don't look like server failures
ErisDS
added a commit
to TryGhost/Ghost
that referenced
this issue
Nov 22, 2022
refs: TryGhost/Product#2289 refs: TryGhost/express-hbs#161 - Themes that resuse layouts as templates trigger horrible errors, which are thrown as 500s - But there's nothing the server is doing wrong, it's a theme user, so we downgrade these to 400s - There is more to do here to improve the errors shown, but this is just a first step to ensure that theme issues don't look like server failures
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This only affects production mode where templates get cached.
Assuming you have a default.hbs file which is your base layout file.
In the case that you load and use default.hbs as a template before loading it as a layout, it will break the layout of all other pages that use the default.hbs layout. This issue will cause what appear to be intermittent layout bugs, because it depends on the order the files get used in...
If you load a page that uses
default.hbs
as a template first, you'll then get "Cannot read property 'match' of undefined" when trying to load the page that usesdefault.hbs
as a layout.If you load a page that uses
default.hbs
as a layout first, you'll get a blank page when trying to load any pages that use it as a template.This is a super crazy edgecase and I don't think it necessarily needs fixing, just raising it as it caused TryGhost/Ghost#10990 and it's useful to know if you're working with express-hbs.
There's a lot more detail about the weird behaviour in TryGhost/Ghost#10990
The text was updated successfully, but these errors were encountered: