Keystone.JS 多个部分文件夹和更改名称

Keystone.JS multiple partial folders and changing name

我对keystone.js的templates/views文件夹中的partial文件夹有几个问题(使用handlebars):

1) 是否可以有多个partials文件夹? (如果是,你是怎么做到的?)

2) 我可以更改文件夹的名称吗?

您可以在 templates/views/partials 目录中创建子目录。

比如可以创建目录templates/views/partials/sub,创建文件myPartial.hbs,然后你可以像这样将它包含在另一个文件中:

{{> sub/myPartial }}

KeystoneJS 将处理 .hbs 文件在 templates/views/partials 目录及其中的任何子目录中的注册。

您可以更改项目根目录中 keystone.js 文件中 partials 目录的名称。

找到传递给keystone.init()'custom engine'选项并更改[=29的值=]partialsDir:

'custom engine': handlebars.create({
  layoutsDir: 'templates/views/layouts',
  partialsDir: 'templates/views/new-partials',
  defaultLayout: 'default',
  helpers: new require('./templates/views/helpers')(),
  extname: '.hbs',
}).engine,

您还可以使用数组创建多个部分目录:

'custom engine': handlebars.create({
  layoutsDir: 'templates/views/layouts',
  partialsDir: ['templates/views/partials', 'templates/views/other-partials'],
  defaultLayout: 'default',
  helpers: new require('./templates/views/helpers')(),
  extname: '.hbs',
}).engine,