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

The {{#get}} helper #5619

Merged
merged 1 commit into from
Oct 15, 2015
Merged

The {{#get}} helper #5619

merged 1 commit into from
Oct 15, 2015

Conversation

ErisDS
Copy link
Member

@ErisDS ErisDS commented Jul 31, 2015

closes #4439

  • adds basic get helper which works with the current API
  • allows theme developers to make requests against the API
  • supports block params and @error message
  • includes 100% test coverage using posts

The {{#get}} helper is an asynchronous block helper which allows for making
requests for data from the API. This allows theme developers to customise the
data which can be shown on a particular page of a blog.

Requests can be made to the posts, tags or users API endpoints:

{{#get "posts" limit="3"}}
  {{#foreach posts}}
     <a href="{{url}}">{{title}}</a>
  {{/foreach}}
{{/get}}

The {{#get}} helper must be used as a block helper, it supports {{else}}
logic, for when no data matching the request is available or if an error has
occurred:

{{#get "posts" tag="photo"}}
  ...
{{else}}
  {{#if @error}}
    <p>Something went wrong: {{@error}}</p>
  {{else}}
    <p>No posts found</p>
  {{/if}}
{{/get}}

The helper also supports block params, meaning the data it outputs can be
given a different name:

{{#get "posts" featured="true" as |featured|}}
  {{#foreach featured}}
    ...
  {{/foreach}}
{{/get}}

Please Note: At present asynchronous helpers cannot be nested.

closes TryGhost#4439

- adds basic get helper which works with the current API
- allows theme developers to make requests against the API
- supports block params and @error message
- includes 100% test coverage using posts

----

The `{{#get}}` helper is an asynchronous block helper which allows for making
requests for data from the API. This allows theme developers to customise the
data which can be shown on a particular page of a blog.

Requests can be made to the posts, tags or users API endpoints:

```
{{#get "posts" limit="3"}}
  {{#foreach posts}}
     <a href="{{url}}">{{title}}</a>
  {{/foreach}}
{{/get}}
```

The `{{#get}}` helper must be used as a block helper, it supports `{{else}}`
logic, for when no data matching the request is available or if an error has
occurred:

```
{{#get "posts" tag="photo"}}
  ...
{{else}}
  {{#if @error}}
    <p>Something went wrong: {{@error}}</p>
  {{else}}
    <p>No posts found</p>
  {{/if}}
{{/get}}
```

The helper also supports block params, meaning the data it outputs can be
given a different name:

```
{{#get "posts" featured="true" as |featured|}}
  {{#foreach featured}}
    ...
  {{/foreach}}
{{/get}}
```

Please Note: At present asynchronous helpers cannot be nested.
@ErisDS ErisDS changed the title [WIP] {{#get}} helper The {{#get}} helper Oct 11, 2015
@ErisDS
Copy link
Member Author

ErisDS commented Oct 11, 2015

This PR is no longer a WIP!

This version of the helper works with the current API, handles itself well when used incorrectly and also handles errors from the API. It should be good to merge as a first pass. Unit test coverage is at 100%:

It will need updating when the API has been improved to have the filter parameter, but that can be done as a separate PR later.

@DanielTamkin
Copy link

I'm so excited for this helper. Glad to see the fast progress on this guys!

sebgie added a commit that referenced this pull request Oct 15, 2015
@sebgie sebgie merged commit 611f1e9 into TryGhost:master Oct 15, 2015
@flpms
Copy link

flpms commented Oct 15, 2015

This helper work on tags and stable for production? Its a great helper. :) 👍

@ErisDS ErisDS deleted the issue-4439-get branch October 15, 2015 18:15
@ErisDS
Copy link
Member Author

ErisDS commented Oct 15, 2015

The helper has only just been merged into master, and master should not be considered stable for production. The helper will be included in the next stable release, when other related parts of the API are complete.

@DanielTamkin
Copy link

This is great to hear @ErisDS !

@PDXIII
Copy link

PDXIII commented Oct 15, 2015

Awesome!

@leotm
Copy link

leotm commented Oct 16, 2015

Great stuff!

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

Successfully merging this pull request may close these issues.

Query (get) helper
6 participants