简体   繁体   English

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

[英]Is it possible to register custom helpers in Ghost?

I am using Ghost as an npm module following this guide .我按照本指南使用 Ghost 作为 npm 模块。

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?有没有办法在不更改 Ghost 模块内的代码的情况下做到这一点?

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.我认为一个可能的问题是我的hbs是一个新的把手实例,与 Ghost 使用的不同,因此当 Ghost 运行时,它不包含我注册的任何帮助程序。

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.我试图提出我自己的基于 3 文件的解决方案,它将采用原始的 Ghost Dockerfile 并从那里构建,仅从一个目录添加自定义帮助程序。

Find it here:在这里找到它:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM