Skip to content

Instantly share code, notes, and snippets.

@stenehall
Forked from tdack/README.md
Last active September 7, 2018 18:07
Show Gist options
  • Save stenehall/3e7a71cf3e46de24bc5116967771ccc9 to your computer and use it in GitHub Desktop.
Save stenehall/3e7a71cf3e46de24bc5116967771ccc9 to your computer and use it in GitHub Desktop.
Custom handlebars helpers for Ghost, as an app

Custom Handlebars Helpers for Ghost

This is a Ghost "App" that will implement a custom Handlebars helper the same as https://apatchofcode.com/adding-custom-handlebars-for-ghost-equals-awesome/

Installation

Create a new directory in contents/apps

eg:

mkdir contents/apps/gt

Place package.json and index.js in the directory.

To enable the app you need to manually add it to the database as described at: https://github.com/TryGhost/Ghost/wiki/Apps-Getting-Started-for-Ghost-Devs

Restart ghost

Usage

Simply use the new helper in your template, eg:

{{#compare 'apples' '===' 'oranges'}}
    <p>Totally not the case.<p>
{{/compare}}
{{#compare 'apples' 'typeof' 'string'}}
    <p>I think we're onto something.<p>
{{/compare}}
var App = require('ghost-app'),
gt
gt = App.extend({
install: function() {},
uninstall: function() {},
activate: function() {
this.app.helpers.register('gt', function(a, b) {
var next = arguments[arguments.length - 1]
return a > b ? next.fn(this) : next.inverse(this)
})
},
deactivate: function() {}
})
module.exports = gt
{
"name": "gt",
"version": "0.0.1",
"dependencies": {
"ghost-app": "0.0.2"
},
"ghost": {
"permissions": {
"helpers": [
"gt"
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment