Skip to content

Query (get) helper #4439

@ErisDS

Description

@ErisDS

One of the main new features we need to add to Ghost is a 'query helper' for themes. This is a helper that gives theme developers access to the API to make custom queries for data they'd like to display.

This helper will only provide access to the GET API endpoints that don't require user authentication - that is getting published posts, and all tags, with all the sorting and filtering options which are available.

I propose that this helper be a block helper called 'fetch':

{{#fetch}}
  .. do stuff with the data here
{{/fetch}}

After that, there are a number of ways we could specify the details of the API call we want to make:

  1. Just accept a string parameter that contains the API call URL:
    {{#fetch "/posts/?limit=5"}}
    {{#fetch "/posts/12/?include=tags"}}
  2. Take the resource as a parameter, and use named attributes for the query params:
    {{#fetch "posts" limit="5"}}
    {{#fetch "posts" id="12" include="tags"}}
  3. Also have the resource be a named attribute:

{{#fetch resource="posts" limit="5"}}
{{#fetch resource="posts" id="12" include="tags"}}

  1. Some other format?

We need to find a format that makes sense to theme developers. Using the API call URL as a string is very simple to implement, but all the /'s and ?'s and &'s look quite complex even though URLs are fairly well understood thing.

The second option is kind of inconsistent with itself, but it looks nice. It's also similar to doing something like {{date published_at format="dd mm YY"}} where there can be a parameter and an attribute, and just like the date helper defaults to published_at, the fetch helper can default to posts.

The third one makes everything consistent, but as soon as you start using named parameters you need to do something like id="12" or slug="welcome-to-ghost" if you want to specify an id, or a slug etc to fetch a specific resource.

Thoughts on a postcard please!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions