Here following the ghost Cheatsheet for the developers :
General Snippets
{{body_class}}
– To show the body class
{{meta_title}}
– To show the meta title
{{ghost_head}}
– To Show the header meta and other codes
{{ghost_foot}}
– To Show the footer codes
@site Data
{{@site.lang}}
– Configured site language. ( Ex: en, es )
{{@site.url}}
– To Show the site URL
{{@site.description}}
– To Show the site Description / Slogan
{{@site.logo}}
– To Show the site logo URL
{{@site.facebook}}
– Facebook URL from general settings
{{@site.twitter}}
– Twitter URL from general settings
{{@site.icon}}
– The publication icon from general settings
{{@site.cover_image}}
– Site cover image from general settings
{{@site.timezone}}
– Timezone as configured in general settings
{{@site.navigation}}
– Navigation information configured in settings/design
Navigation
A navigation item has the following attributes which can be used inside your ./partials/navigation.hbs template file…
{{label}}
– The text to display for the link
{{url}}
– The URL to link to – see the url helper for more options
{{current}}
– Boolean true / false – whether the URL matches the current page
{{slug}
– Slugified name of the page, eg about-us. Can be used as a class to target specific menu items with CSS or jQuery.
Example:
<div class="my-fancy-nav-wrapper"> <ul class="nav"> <!-- Loop through the navigation items --> {{#foreach navigation}} <li class="nav-{{slug}}{{#if current}} nav-current{{/if}}"><a href="{{url absolute="true"}}">{{label}}</a></li> {{/foreach}} <!-- End the loop --> </ul> </div>
Condition to Detect index, page, post etc
{{#is "index"}}{{/is}}
– To detect the index page
{{#is "home"}}{{/is}}
– To detect the home page
{{#is "post"}}{{/is}}
– To detect the single post page
{{#is "page"}}{{/is}}
– To detect the single page
{{#is "author"}}{{/is}}
– To detect the author page
{{#is "tag"}}{{/is}}
– To detect the tag page
{{#is "paged"}}{{/is}}
– To detect if this is page 2, page 3 of a list, but not on the first page
{{#is "private"}}{{/is}}
– To detect the private page shown for password protected sites
Example:
{{#is "home"}} ... output something special for the home page ... {{else}} ... output something different on all other pages ... {{/is}}
Example:
{{#is "post, page"}} ... content to render if the current route represents a post or a page ... {{/is}}
foreach
{{#foreach data}}{{/foreach}}
– Special loop helper for lists of posts,tags or users
Example:
{{#foreach posts limit="3"}} <a href="{{url}}">{{name}}</a> {{/foreach}}
Example 4:
{{#foreach posts from="2" to="5"}} <a href="{{url}}">{{name}}</a> {{/foreach}}
Data Variables For foreach
@index
(number) – the 0-based index of the current iteration
@number
(number) – the 1-based index of the current iteration
@key
(string) – if iterating over an object, rather than an array, this contains the object key
@first
(boolean) – true if this is the first iteration of the collection
@last
(boolean) – true if this is the last iteration of the collection
@odd
(boolean) – true if the @index is odd
@even
(boolean) – true if the @index is even
@rowStart
(boolean) – true if columns is passed and this iteration signals a row start
@rowEnd
(boolean) – true if columns is passed and this iteration signals a row end
Example:
{{#foreach posts}} {{#if @first}} <div>First post</div> {{/if}} {{/foreach}}
Example:
{{#foreach posts}} <div class="{{#if @even}}even{{else}}odd{{/if}}">{{title}}</div> {{/foreach}}
has
{{#has}}
is like {{#if}}
but with the ability to do more than test a boolean. It allows theme developers to ask questions about the current context and provide more flexibility for creating different layouts.
{{#has tag="value1,value2" author="value"}}
{{#has slug=../slug}}
{{#has number="nth:3"}}
{{#has any="twitter, facebook"}}
{{#has all="twitter, facebook"}}
Inject widget partial every 3rd post
Example:
{{#foreach posts}} {{#has number="nth:3"}} {{> "widget"}} {{/has}} {{> "post-card"}} {{/foreach}}
Foreach loop number or index
Example:
{{#has number="3"}}{{/has}} // A single number {{#has number="3, 6, 9"}}{{/has}} // list of numbers {{#has number="nth:3"}}{{/has}} // special syntax for nth item {{!-- All of these work exactly the same for index --}}
if
{{#if featured}}{{/if}}
– allows for testing if featured post
Example:
{{#post}} {{#if feature_image}} <img src="{{img_url feature_image}}" /> {{else}} <img src="{{asset "img/default-img.jpg"}}" /> {{/if}} {{else}} <p>No posts to display!</p> {{/post}}
unless
{{#unless featured}}{{/unless}}
-That is essentially the opposite of {{#if}}
get
That makes a custom query to the Ghost API to fetch publicly available data
{{#get "posts" limit="20"}}{{/get}}
– Fetch the 20 most recently published posts
{{#get "posts" limit="all"}}{{/get}}
– Fetch all published posts
{{#get "posts" [email protected]_per_page}}{{/get}}
– Use the posts_per_page setting
{{#get "posts" limit="5" page="4"}}{{/get}}
– Fetch the 4th page of results – In this case where limit = 5, we are accessing posts 16 – 20
{{#get "posts" limit="5" order="published_at asc"}}{{/get}}
– Fetch the oldest 5 posts
{{#get "posts" limit="5" order="published_at desc"}}{{/get}}
– Fetch the 5 most recently published posts
{{#get "posts" limit="5" order="title asc"}}{{/get}}
– Fetch posts in alphabetical order of title ([0-9], A->Z)
{{#get "posts" limit="all" filter="featured:true"}} {{/get}}
– Fetch all featured post
{{#get "posts" filter="authors:{{primary_author.slug}}+id:-{{id}}" limit="3"}} {{/get}}
– Fetch primary_authors 3 posts
{{#get "posts" filter="primary_tag:{{primary_tag.slug}}" limit="3"}}{{/get}}
– Featch 3 posts of same primary tag
{{#get "posts" limit="5" include="authors,tags"}}{{/get}}
– Fetch posts with author and tags
No Comment