javascript - 是否可以在 Ghost 中注册自定义助手?

标签 javascript node.js handlebars.js ghost

我正在使用 Ghost 作为 this guide 之后的 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());

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

最佳答案

不幸的是,即使使用最新版本,这仍然是一个非常近期的问题。我试图提出自己的基于 3 文件的解决方案,该解决方案将采用原始的 Ghost Dockerfile 并从那里构建,仅从一个目录添加自定义帮助程序。
在这里找到它:

  • https://hub.docker.com/r/activenode/ghost-docker-custom-helpers
  • https://github.com/activenode/ghost-docker-custom-helpers
  • 关于javascript - 是否可以在 Ghost 中注册自定义助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38104513/

    相关文章:

    javascript - 不确定正在使用哪个 JS 模板引擎

    javascript - 如何在 Hogan.js 中使用助手

    javascript - 在javascript中实例化一个新类时,不将其分配给变量有什么危害?

    Javascript document.write() 指向另一个页面

    node.js - WebStorm/grunt 调试运行抛出 EADDRINUSE 错误

    node.js - Mongoose 在第二个请求时打开 2 个到数据库的连接

    javascript - 如何在 Nodejs 服务器上呈现带有 Handlebars 的静态 HTML 文件?

    javascript - 如果今天是当天,则打开叠加层

    javascript - 如何在js中读取一个json对象

    javascript - 这个类声明中使用的 Javascript 格式是什么?