Usage: {{#get "posts"}}{{/get}}
{{#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.
{{#get}}
helper has several more options that greatly extend its functionality. The following section walks through these options and how to use them.
"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:
{{#foreach}}
helper, use block parameters to rename your returned data collection to make it easier to reference or more distinguishable.
|
){{#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.
{{else}}
{{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.
{{#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.
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:
{{#get}}
query will be paginated. Choose which page of that collection you want to get with the page
attribute.
Example:
asc
) or descending (desc
) order.
Examples:
{{#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:
count.posts
to order your collection.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.
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.
filter
filter
attribute.
title
, dates
, or other values with spaces to filter
–wrap the data in single quotes.
{{published_at}}
, not the {{date}}
helper, as helper functions do not get called inside of a filter.primary_tag
represents the first tag on a post. See the available attributes.
primary_author
represents the first author listed on a post. See the available attributes.
{{#get}}
helper, filter the collection using the type
attribute with either free or paid.
{{#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.