小编thg*_*ell的帖子

是否可以在Ghost中注册自定义帮助程序?

我按照本指南使用Ghost作为npm模块.

我想添加一些我可以在我的主题中使用的自定义助手.有没有办法在不更改Ghost模块内的代码的情况下执行此操作?

这是我目前的代码:

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());
Run Code Online (Sandbox Code Playgroud)

我认为一个可能的问题是我hbs是一个新的把手实例,与Ghost使用的不同,因此当Ghost运行时它不包括我注册的任何助手.

javascript node.js handlebars.js ghost

7
推荐指数
1
解决办法
500
查看次数

标签 统计

ghost ×1

handlebars.js ×1

javascript ×1

node.js ×1