Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to register custom helpers in Ghost?

I am using Ghost as an npm module following this guide.

I would like to add some custom helpers that I can leverage inside of my themes. Is there a way to do this without changing code inside the Ghost module?

This is my current code:

const ghost = require('ghost');
const path = require('path');
const hbs = require('express-hbs');

const config = path.join(__dirname, 'config.js');
const coreHelpers = {};

coreHelpers.sd_nls  = require('./sd_nls');

// Register a handlebars helper for themes
function registerThemeHelper(name, fn) {
  hbs.registerHelper(name, fn);
}

registerThemeHelper('sd_nls', coreHelpers.sd_nls);

ghost({ config: config })
  .then(ghostServer => ghostServer.start());

I think one possible problem is that my hbs is a new handlebars instance, not the same one used by Ghost, therefore when Ghost runs it doesn't include any helpers I've registered.

like image 847
JuanCaicedo Avatar asked Jun 29 '16 15:06

JuanCaicedo


1 Answers

Unfortunately even with the most recent version this still is a very recent issue. I tried to come up with my own 3-file-based solution that will take the original Ghost Dockerfile and build from there adding custom helpers from just one directory.

Find it here:

  • https://hub.docker.com/r/activenode/ghost-docker-custom-helpers
  • https://github.com/activenode/ghost-docker-custom-helpers
like image 87
androidavid Avatar answered Sep 29 '22 17:09

androidavid