question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Themes: get helper, querying by slug not working

See original GitHub issue

Issue 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

  1. Enable the public API
  2. Open index.hbs and paste the find-by-slug example from the docs
  3. Edit the slug to match a published post
  4. Restart the Ghost service
  5. 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ErisDScommented, Apr 3, 2017

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:

{{#get "posts" slug="welcome-to-ghost" as |post|}} 
{{#post}}
   <h2><a href="{{slug}}">{{title}}</a></h2> 
   <div class="post-content"> {{content}} </div>
{{/post}} 
{{/get}}

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.

0reactions
kirrg001commented, Jun 14, 2017

I have updated http://themes.ghost.org/docs/get and http://themes.ghost.org/v0.11.9/docs/get 👍

Thanks again for the report 😎

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found