mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 16:14:25 +03:00
3e40637cd4
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. |
||
---|---|---|
.. | ||
test_tpl | ||
asset_spec.js | ||
author_spec.js | ||
body_class_spec.js | ||
content_spec.js | ||
date_spec.js | ||
encode_spec.js | ||
excerpt_spec.js | ||
foreach_spec.js | ||
get_spec.js | ||
ghost_foot_spec.js | ||
ghost_head_spec.js | ||
has_spec.js | ||
image_spec.js | ||
input_password_spec.js | ||
is_spec.js | ||
meta_description_spec.js | ||
meta_title_spec.js | ||
navigation_spec.js | ||
next_post_spec.js | ||
page_url_spec.js | ||
pagination_spec.js | ||
plural_spec.js | ||
post_class_spec.js | ||
prev_post_spec.js | ||
tags_spec.js | ||
title_spec.js | ||
url_spec.js | ||
utils.js |