Skip to content
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

Themes: get helper, querying by slug not working #8245

Closed
thopanX opened this issue Apr 1, 2017 · 5 comments
Closed

Themes: get helper, querying by slug not working #8245

thopanX opened this issue Apr 1, 2017 · 5 comments
Assignees
Milestone

Comments

@thopanX
Copy link

thopanX commented Apr 1, 2017

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
@kirrg001
Copy link
Contributor

kirrg001 commented Apr 3, 2017

Hey @thorsten-panknin 👋

This doesn't work for me neither. Sorry for trouble.

A workaround for you would be to use the following syntax:

{{#get "posts" slug="welcome-to-ghost"}}
  {{#foreach posts}}
    <h2><a href="{{slug}}">{{title}}</a></h2>
  {{/foreach}}
{{/get}}

There is no problem with the result of the api response, the post is there, just the #post notation does not work. The #get result does not contain a post attribute. I will keep the issue open, will figure out why.

@ErisDS
Copy link
Member

ErisDS commented 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: #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.

@ErisDS ErisDS self-assigned this Apr 3, 2017
@ErisDS ErisDS added the LTS label Apr 3, 2017
@ErisDS ErisDS added this to the 1.0.0 Launch milestone Apr 3, 2017
@thopanX
Copy link
Author

thopanX commented Apr 3, 2017

@kirrg001 Thanks, the workaround works fine.

@ErisDS Thanks for your efforts as well.

@kirrg001 kirrg001 modified the milestones: Next LTS release, 1.0.0 Backlog May 12, 2017
@kirrg001 kirrg001 modified the milestones: Upcoming LTS release, 0.11.9 May 12, 2017
@Dreyfuzz
Copy link

Dreyfuzz commented Jun 2, 2017

Same problem with querying by id in the documentation. Should be updated.

@kirrg001 kirrg001 self-assigned this Jun 14, 2017
@kirrg001
Copy link
Contributor

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

Thanks again for the report 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants