0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/server
Hannah Wolfe 3e40637cd4 The {{#get}} helper
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.
2015-10-11 16:51:12 +01:00
..
api Return a single 422 error for invalid values 2015-09-25 10:30:49 +01:00
apps Merge pull request #5027 from felixrieseberg/iss4847 2015-03-19 10:47:01 -06:00
config Test support for various URL schemes 2015-09-27 10:31:49 +01:00
controllers Returns 404 page instead of crashing a server whenever special characters are used for tag filtering 2015-09-20 22:47:34 +02:00
data Merge pull request #5892 from yanntech/fix/pg-upgrade 2015-10-08 08:54:12 +01:00
errors Return a single 422 error for invalid values 2015-09-25 10:30:49 +01:00
events Refactor sitemaps to use centralised events 2015-04-05 19:32:18 +01:00
helpers The {{#get}} helper 2015-10-11 16:51:12 +01:00
mail Mail consolidation 2015-08-20 11:36:14 +02:00
middleware Remove unnecessary API lookup for activeTheme 2015-09-29 22:54:55 +02:00
models Remove findAll from models that has findPage 2015-10-02 18:01:35 +08:00
permissions Refactor handlePermissions 2015-08-11 16:03:57 +02:00
routes add author edit route 2015-09-23 08:33:09 -05:00
storage Merge pull request #4820 from phated/file-storage 2015-03-20 08:55:19 +00:00
translations foundation work for server-side i18n support: 2015-07-27 18:47:10 -04:00
utils Fix handling of slugs on import 2015-09-23 17:41:44 +01:00
views Fixup broken error page styles 2015-06-08 12:14:58 +01:00
filters.js Misc grunt /dev updates 2015-05-28 20:25:14 +01:00
ghost-server.js Startup message explicitly mentions production 2015-08-11 18:01:36 +01:00
i18n.js foundation work for server-side i18n support: 2015-07-27 18:47:10 -04:00
index.js Remove first run alert 2015-08-26 15:29:26 +01:00
require-tree.js Misc grunt /dev updates 2015-05-28 20:25:14 +01:00
update-check.js Remove forum mentions 2015-09-29 13:10:04 +02:00