10

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.

thgaskell
  • 12,772
  • 5
  • 32
  • 38
JuanCaicedo
  • 3,132
  • 2
  • 14
  • 36

1 Answers1

2

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:

androidavid
  • 1,258
  • 1
  • 11
  • 20