Skip to main content

{{#get}} is a special block helper that makes a custom query to the Ghost API to fetch publicly available data. These requests are made server-side before your templates are rendered. This means you can fetch additional data, separate from what is provided by default in each context. In its most basic form, the {{#get}} helper performs a “browse” query that creates a block of data that represents a list of your posts, authors, tags, or tiers. Use the {{#foreach}} helper to iterate over this block of data. The {{#get}} helper can also be used to perform a “read” query that fetches one specific author, post, tag, or tier when the relevant resource field - e.g., id or slug – is provided as an attribute.

Basic examples

Get the 15 newest posts from the API.
Get a single post with the id of 2, including its related tags and author data, using a block parameter. Learn more about block parameters below.
Fetch all tags and output them using the tags helper.

Usage

The {{#get}} helper has several more options that greatly extend its functionality. The following section walks through these options and how to use them.

Resources

The first parameter passed in is the name of the resource you want to query. Available resources include: "posts", "tags", "authors", and "tiers". posts - any published post tags - any tag that has a post associated with it authors - any author who has published a post tiers - any membership tier newsletters - any newsletter Example:

Block parameters

As with the {{#foreach}} helper, use block parameters to rename your returned data collection to make it easier to reference or more distinguishable.
Block parameters are entered between pipe symbols (|)
The {{#get}} helper supports two parameters. The first entry refers to your returned data collection. The second entry refers to your pagination object. Block parameters example: Get posts and rename the collection articles. The additional pagination object, pages, outputs the total number of posts in the collection.

Using {{else}}

All block helpers support the {{else}} helper, which outputs content when the first block doesn’t match. In the case of the {{get}} helper, this only happens if there’s an error and is mostly useful for debugging while developing. To output different content when there are no results returned from the {{#get}} request, use {{else}} with the {{#foreach}} helper.

Attributes

Use {{#get}} helper attributes to specify which data is returned. Available attributes are identical to those used with the Ghost Content API. “Browse” requests (fetching multiple items) accept any or all of these attributes. “Read” requests (fetching a single item by id or slug) only accept the include attribute.

limit

How many items to return Allowed values: 1-100 Default value: 15 Requesting more than 100 items will return a maximum of 100 items It’s possible to use the global posts_per_page setting, which is 5 by default. Configure the setting in the active theme’s package.json file. This global value is available via the @config global as @config.posts_per_page. Examples:

page

when the total number of posts exceeds the number of post initially requested, the resulting collection from the {{#get}} query will be paginated. Choose which page of that collection you want to get with the page attribute. Example:

order

Specify how your data is ordered before being returned. You can choose any valid resource field in ascending (asc) or descending (desc) order. Examples:

include

By default, the {{#get}} helper will only fetch the base data from a resource. Use include to expand the data that is returned. Separate multiple include values with a comma. Base resource data:
  • posts
  • tags
  • authors
  • tiers
Include options for Post:
  • “authors” – adds author data
  • “tags – adds tag data
Include option for Author and Tag
  • “count.posts” – adds the post count for each resource
Use count.posts to order your collection.
Include options for Tiers
  • “monthly_price” - add monthly price data
  • “yearly_price” – add yearly price data
  • “benefits” – add benefits data
Examples:

filter

Use filter to make complex, logic-based queries on the data to fetch. In its most basic form, use filter to get posts that meet a simple boolean condition.
Specify multiple rules for the filter attribute by using , for or, + for and, and - for negation. It’s possible to check for booleans, match against strings, look for items within a group, and much more. For a full breakdown of the filtering syntax and how to use it, please see the filter documentation in the API docs.

Passing data to filter

Data already available within your theme template can be passed to the filter attribute.
When passing title, dates, or other values with spaces to filter–wrap the data in single quotes.
Tip: To filter based on dates, use the data attributes, e.g.{{published_at}}, not the {{date}} helper, as helper functions do not get called inside of a filter.

Filtering by primary tag

The primary_tag represents the first tag on a post. See the available attributes.

Filtering by primary author

The primary_author represents the first author listed on a post. See the available attributes.

Filtering by membership type

To restrict the type of tiers returned by the {{#get}} helper, filter the collection using the type attribute with either free or paid.

Filtering by tier visibility

To restrict the visibility of tiers returned by the {{#get}} helper, filter the collection using the visibility attribute with either public or none. Visibility here refers to whether the tier is selected or not in Portal settings.