Code Snippets for Ghost

by ElectronThemes in Ghost on April 4, 2019

I am developing ghost themes for over 2 years. Always I try to follow ghost docs, but the problem is I have to find the codes. So I have tried to organize all useful code in one place. You will find your necessary codes here.

General options

Single post

Language{{@site.lang}}this code is for language
Title{{meta_title}for meta title
Site logo{{@site.logo}}for showing site logo
Description{{@site.description}}for meta description
Site url{{ @site.url }}Show the site url
Facebook{{@site.facebook}}Site’s facebook profile
Facebbok URL{{facebook_url}}URL for facebook profile
Twitter{{@site.twitter}}Site’s twitter profile
Twitter URL{{twitter_url}}URL for twitter profile
Assets{{asset}}for all assets to import
Default{{!< default}}Call Default.hbs file
Partials{{> "header"}}Call the file from partials
is{{#is "page"}}{{/is}}Render the data only for page. See more here
Body Class{{body_class}}Show all body class here
Scripts{{{block "scripts"}}}Show the script here
Head{{ghost_head}}Show the header meta and other codes here
Foot{{ghost_foot}}Ghost footer here
Post_per_page"posts_per_page": 7Show posts per page
Pagination{{pagination}}Show pagination
Post number{{plural ../ empty='No Post' singular='% Post' plural='% Posts'}}Show post number under single tag or author
Condition{{#if}}{{/if}}if condition for the content
Negative Condition{{#if}}{{/if}}if negative condition for the content
Condition{{#has}}{{/has}}has condition for the content
Negative Condition{{^has}}{{/has}}has negative condition for the content
Show specific number{{has number="1"}}{{/has}}Show specific number post


Author{{#tag}}{{/tag}}Show tag content of single tag page
Name{{name}}Name of tag
URL{{url}}URL of the tag
Feature image{{feature_image}}feature image of tag
Description{{description}}a description of the tag
Meta title{{meta_title}}custom meta title for the page
Meta descriptionmeta_descriptionCustom meta description for the page –url– the web address for the tag’s page


Author{{#author}}{{/author}}Show author content of single author page
Name{{name}}Name of authors
Cover{{cover_image}}Cover photo of author
Location{{location}}Location for the author
image{{profile_image}}Profile photo of author
Bio{{bio}}Bio for the author
URL{{url}}URL of the author
Facebook{{facebook}}Facebook profile of author
Facebook URL{{facebook_url}}Facebook URL for the author
Twitter{{twitter}}Twitter account for the author
Twitter URL{{twitter_url}}Twitter URL for the author
Website{{website}}Website of author

Get – Fetch the data

This is used to fetch the postsauthorstags.

Posts{{#get "posts" include="tags,authors"}}{{/get}}Get all posts
Featured posts{{#get "posts" filter="featured:true" include="tags,authors"}}{{/get}}Get all posts
Specific Tag Posts{{#get "posts" filter="tag:portfolio" include="tags,authors"}}{{/get}}Get all posts of portfolio tag
Author Posts{{#get "posts" filter="tag:enamul" include="tags,authors"}}{{/get}}Get all posts of portfolio tag
Author list{{#get "authors" include="count.posts"}}{{/get}}Get all authors of the site
Tag list{{#get "tags" include="count.posts"}}{{/get}}Get all tags of the site
Related posts{{#get "posts" limit="3" include="tags,authors" filter="id:-{{comment_id}}+tag:{{primary_tag.slug}}" as |relatedPost|}}{{/get}}Show all related posts
Optionslimit="all"Limit the posts
limit=@config.posts_per_pageLimit the posts as per config
page="4"To show the specific page posts
order="published_at asc"Show post on specific order
order="title asc"Show post on title order
include="tags,authorsIncludes will fetch the tags/authors data


Message{{message}}Error message
Code{{code}}Code of errors


{{#foreach navigation}}
<li class="{{#if current}}active{{/if}}">
   <a href="{{url absolute="true "}}">{{label}}</a>


{{#if @labs.subscribers}}
{{subscribe_form input_class="form-control"  placeholder="Enter your email address"  form_id="subscribe"  form_class="d-flex"}}

Code Highlighter

// Code highlightBlock
var  activateHighlight  =  function() {
	document.querySelectorAll("pre code").forEach(
		function(currentValue, currentIndex, listObj){
if (window.attachEvent) {
	window.attachEvent('onload', loadHighlight);
} else {
	if (window.onload) {
		var originalOnload = window.onload;
		var  newOnload  =  function  (evt)  {
		window.onload  = newOnload;
	} else {
		window.onload  = activateHighlight;

Disqus comment

var  disqus_config  =  function () {  =  "{{url absolute="true"}}";  =  "ghost-{{comment_id}}";
(function () {  // DON'T EDIT BELOW THIS LINE
	var d = document, s = d.createElement('script');
	s.src  =  '';
	s.setAttribute('data-timestamp',  +new  Date());
	(d.head  || d.body).appendChild(s);