Public API doesn't work in error.hbs template
See original GitHub issueIssue Summary
Public API doesn’t work in error.hbs template
Steps to Reproduce
- I had tried use this code for testing error page with enabled api
$.get(ghost.url.api('posts', {limit: "all", include: "tags"})).done(function(data){
searchData = data.posts;
console.log(searchData);
})
and I get this message:
ghost is not defined
Technical details:
- Ghost Version: 0.8.0
- Node Version: 0.12.7
- Browser/OS: chrome
- Database: mysql
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Handlebars example not working - Stack Overflow
I realized the problem. The server-side handlebars is interfering with client-side handlebars. All the {{}} tags that are meant for the client- ...
Read more >hbs files are not copied to dist folder · Issue #42 - GitHub
I'm still getting the error that implies that the templates folder is not transpiled to the dist folder. What could the problem possibly...
Read more >How to Handle Errors in an Express and Node.js App
Express knows this and makes handling errors in our API a breeze. In this post, I will explain how to handle errors in...
Read more >Introduction | Handlebars
Handlebars is a simple templating language. It uses a template and an input object to generate HTML or other text formats.
Read more >Node.js application error message: "Cannot GET" URL
js application error message: "Cannot GET" URL. This article discusses a problem that may occur when you try to run a Node.js application...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve always considered that it is bad practice to use the main layout on the error page, and more specifically to include ghost_head or foot on the error template. I think it’s better to have a 500 error page that can render freely of any other aspect of the software, to minimise the chance of causing the error to be thrown again.
The server-side error environment is quite different to rendering a normal page of your theme, lots of things aren’t loaded, and the reason for this particular issue is that if you call ghost_head from an error page it simply exits rather than adding anything, so as not to cause any more errors…
The default error template provided by Ghost is entirely stand-alone as an example of what we consider best practice here. You can see this file here: user-error.hbs.
However, I’ve seen that using the default layout in the error template is common amongst themes, and I have a feeling the reason for that is symptom of a different problem - the fact that
error.hbs
is used for both 404s as well as 5xx errors. It’s pretty common to want to heavily customise a 404 page and render all sorts of useful stuff (such as search) on that page to get a user to stay on the site, meanwhile I think it’s fairly standard to have a very simple 5xx template.I’d propose extending the error handling system to support error-404.hbs and error-500.hbs, to handle different sorts of errors differently. I’d propose that ghost_head should still not output anything if we’re on a 500 or 5xx error, but that it would be ok to output some things (such as the API scripts) if we’re on a 404 page?
Closing in favour of the feature spec: #8079