Skip to content

Instantly share code, notes, and snippets.

@sethbergman
Created April 24, 2018 13:50
Show Gist options
  • Save sethbergman/a2f88ec3cf60097400e5b89ac680c12b to your computer and use it in GitHub Desktop.
Save sethbergman/a2f88ec3cf60097400e5b89ac680c12b to your computer and use it in GitHub Desktop.
Handlebars Ghost Helpers
// Get Posts Get Posts
// This will get the default number of blog posts (15)
{{#get "posts"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get all Posts Get all Posts
{{#get "posts" limit="all"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Posts with Tag and Author Info Included Get Posts with Tag and Author Info Included
// Tag and author data are not included by default
{{#get "posts" include="tags,author"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get a Certain Number of Posts Get a Certain Number of Posts
{{#get "posts" limit="10"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Featured Posts Get Featured Posts
{{#get "posts" filter="featured:true"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Posts with a Certain Tag Get Posts with a Certain Tag
{{#get "posts" filter="tag:sometag"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Posts with Two Different Tags Get Posts with Two Different Tags
{{#get "posts" filter="tag:sometag,tag:othertag"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Posts with Specific Tag and Specific Author Get Posts with Specific Tag and Specific Author
{{#get "posts" filter="tag:sometag+author:authorname"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Posts Ordered by Title Get Posts Ordered by Title
{{#get "posts" order="title asc"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get the 2nd Page of Paginated Posts Get the 2nd Page of Paginated Posts
// If you already have the first posts, or want the next set, you can use the page
// attribute (default post limit is 15)
{{#get "posts" page="2"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get the 2nd Page of a Certain Limit of Posts Get the 2nd Page of a Certain Limit of Posts
// If you want to grab the 2nd page of a certain number of posts (besides the
// default 15), add the limit attribute
{{#get "posts" page="2" limit="5"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Posts by a Specific Author Get Posts by a Specific Author
{{#get "posts" filter="author:authorname"}}
{{#foreach posts}}
//Add html for each post here
{{/foreach}}
{{/get}}
// Get Pages Get Pages
{{#get "posts" filter="page:true"}}
{{#foreach posts}}
//Add html for each page here
{{/foreach}}
{{/get}}
// Get All Pages Get All Pages
{{#get "posts" filter="page:true" limit="all"}}
{{#foreach posts}}
//Add html for each page here
{{/foreach}}
{{/get}}
// Get Pages with Tag Get Pages with Tag
{{#get "posts" filter="page:true+tag:sometag"}}
{{#foreach posts}}
//Add html for each page here
{{/foreach}}
{{/get}}
// Get a Certain Number of Pages Get a Certain Number of Pages
{{#get "posts" filter="page:true" limit="5"}}
{{#foreach posts}}
//Add html for each page here
{{/foreach}}
{{/get}}
// Get Tags Get Tags
{{#get "tags"}}
{{#foreach tags}}
//Add html for each tag here
{{/foreach}}
{{/get}}
// Get All Tags Get All Tags
{{#get "tags" limit="all"}}
{{#foreach tags}}
//Add html for each tag here
{{/foreach}}
{{/get}}
// Get Tags with Post Count Get Tags with Post Count
{{#get "tags" include="count.posts"}}
{{#foreach tags}}
//Add html for each tag here
{{/foreach}}
{{/get}}
// Get All Users Get All Users
{{#get "users" limit="all"}}
{{#foreach users}}
//Add html for each user here
{{/foreach}}
{{/get}}
// Get Users with Post Count Get Users with Post Count
{{#get "users" include="count.posts"}}
{{#foreach users}}
//Add html for each user here
{{/foreach}}
{{/get}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment