Themes: get helper, querying by slug not working
See original GitHub issueIssue Summary
The get helper doesn’t seem to work with the find-by-slug example from the docs.
{{#get "posts" slug="welcome-to-ghost"}} {{#post}} <h2><a href="{{slug}}">{{title}}</a></h2> <div class="post-content"> {{content}} </div> {{/post}} {{/get}}
Steps to Reproduce
- Enable the public API
- Open index.hbs and paste the find-by-slug example from the docs
- Edit the slug to match a published post
- Restart the Ghost service
- Reload browser page
Nothing is output. I tried the tag cloud example from the docs which worked fine.
Technical details:
- Ghost Version: 0.11.7, self-hosted
- Node Version: 4.7.3
- Browser/OS: Firefox 52 on Android
- Database: SQLite
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Ghost Handlebars Theme Helpers: get
Make custom queries to the Ghost API using the get helper and fetch publicly available data. Read more about Ghost themes!
Read more >Query where ANDing slug values not working
You can do this using the WP APIs like this: $args = [ 'post_type' => 'post', 'tax_query' => [ 'relation' => 'AND', ...
Read more >Slugs not matching but links work - WordPress.org
I have a WP page which has been generated by a PHP script. This page contains a links to other pages which contain...
Read more >Custom Post Types query using SLUG as unique identifier ...
Context. I've created a Custom Post Type in WordPress named "projects" and now I'm trying to query a single project using the slug...
Read more >Using Your Theme's Defaults For Easy Query Results
Use Easy Queries to create a custom collection of posts and output them ... that to the slug of the Easy Query you...
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
As I put in Slack, I did a quick investigation and am pretty baffled. This has NEVER worked.
It seems I confused myself. Section 4.1 of this issue: https://github.com/TryGhost/Ghost/issues/5993 explains the problem correctly. The documentation is totally not correct 😞
If you use a blockParam like
as |post|
it would work:Although it does switch between doing either a read or browse request as the docs suggest, the response format is identical. Both return an array, even though the read request only returns a single item.
There is no flattening or extra handling, so unless you use a block param as described above, you would need to use
{{#foreach}}
unlike what the docs say.I am absolutely not sure how I managed to confuse myself here, but this is effectively an error in the documentation - all responses from the get helper are entirely consistent so the documentation is just confusing things!
Gonna count this as a docs bug & fix the docs to say that all results are the same.
I have updated http://themes.ghost.org/docs/get and http://themes.ghost.org/v0.11.9/docs/get 👍
Thanks again for the report 😎