-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
The {{#get}} helper #5619
Conversation
6256804
to
a438e2c
Compare
a438e2c
to
fd285d1
Compare
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.
fd285d1
to
3e40637
Compare
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. |
I'm so excited for this helper. Glad to see the fast progress on this guys! |
This helper work on tags and stable for production? Its a great helper. :) 👍 |
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. |
This is great to hear @ErisDS ! |
Awesome! |
Great stuff! |
closes #4439
The
{{#get}}
helper is an asynchronous block helper which allows for makingrequests 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:
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:
The helper also supports block params, meaning the data it outputs can be
given a different name:
Please Note: At present asynchronous helpers cannot be nested.