【问题标题】:KeystoneJS: site-wide configuration variables in databaseKeystoneJS:数据库中的站点范围配置变量
【发布时间】:2016-09-15 21:42:00
【问题描述】:

当使用 KeystoneJS 创建站点时,我如何添加一些存储在数据库中的站点范围的配置变量 - 最好可以通过管理员进行操作 - 就像 Craft CMS's 'globals' 一样?

我在 Keystone database documentation 中找不到任何关于此的内容,并且尽可能不使用带有 Keystone 列表的单例(例如,通过实现一个只有一个项目的列表)。

【问题讨论】:

    标签: node.js mongodb configuration keystonejs


    【解决方案1】:

    我刚刚与其中一位 Keystone 开发人员就此进行了交谈。一直是widely discussed on ProductPains,事实证明,目前(从 0.3.x 开始)拥有一个带有列表的单例是唯一的方法:

    • 定义一个新模型,例如models/Configuration.js:
    const keystone = require('keystone');
    const Types = keystone.Field.Types;
    
    const Configuration = new keystone.List('Configuration', {
      nocreate: true,
      nodelete: true,
      label: 'Configuration',
      path:  'configuration',
    });
    
    Configuration.add({
      siteName: { type: String },
      siteDescription: { type: Types.Textarea },
    });
    
    Configuration.defaultColumns = 'siteName, siteDescription';
    Configuration.register();
    
    • 添加更新,例如updates/0.0.2-configuration.js:
    exports.create = {
      Configuration: [
        { 'siteName': 'My site', 'siteDescription': 'TODO' }
      ]
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-04
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 2014-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多