question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query (get) helper

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:35 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
ErisDScommented, Jan 14, 2015

Here’s a little bit of how I imagine it working:

In post.hbs, display the 5 most recent posts in a sidebar:

{{#post}}
<article>
  <header><h1>{{title}}</h1></header>
  <section>{{content}}</section>
  <footer>Published at {{date format="DD MMMM YYYY"}}</footer>
</article>
{{/post}}
{{#get "posts" limit="5"}}
  <aside>
    <ol>
    {{#foreach posts}}
      <li>{{title}}</lI>
    {{/foreach}}
    </ol>
  </aside>
{{else}}
  <p>No posts available</p>
{{/get}}

In index.hbs, display a list of all tags in a sidebar:

{{#foreach posts}}
    {{! output partials/post.hbs}}
    {{> "post"}}
{{/foreach}}
{{#get "tags" limit="all" order="alpha"}}
  <aside>
    <ul>
    {{#foreach tags}}
      <li>{{name}}</li>
    {{/foreach}}
  </ul>
</aside>
{{else}}
  <p>No tags available</p>
{{/get}}
0reactions
onlinecommented, Nov 29, 2015

@dbalders thank you, this is just what I need! 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query helper - Solarium PHP Solr client library
You can get a query helper instance by calling the 'getHelper()' method of your query instance. This is available in all query classes....
Read more >
Query Helpers in TypeScript - Mongoose
Query helpers let you define custom helper methods on Mongoose queries. Query helpers make queries more semantic using chaining syntax.
Read more >
Helper functions for M extensions for Power Query connectors
Use helper functions for Power Query connectors. ... Generate( () => getNextPage(null), // get the first page of data (lastPage) => lastPage ...
Read more >
Query Helper Methods — CodeIgniter 3.1.13 documentation
Displays the number of affected rows, when doing “write” type queries (insert, update, etc.). Note. In MySQL “DELETE FROM TABLE” returns 0 affected...
Read more >
Ghost Handlebars Theme Helpers: get
Make custom queries to the Ghost API using the get helper and fetch publicly available data. Read more about Ghost themes!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found