Search code examples
node.jsexpresspugkeystonejs

Keystonejs how to access models in a template


I created a new model and it's showing on admin ui, but how i can acces it from a template?

var keystone = require('keystone'),
    Types = keystone.Field.Types;


var Content = new keystone.List('Content', {
    map: {name: 'title'},
    autokey: {path: 'slug', from: 'title', unique: true }
});


Content.add({
    title: { type: String, required: false },
    state: { type: Types.Select, options: 'draft, published, archived', default: 'archived'},
    author: { type: Types.Relationship, ref: 'User', index: true },
    content: {
        brief: { type: Types.Html, wysiwyg: true, height: 100  }
    }
});

Content.defaultColumns = 'title';
Content.register();

Solution

  • var keystone = require('keystone');
    
    exports = module.exports = function(req, res) {
    
    var view = new keystone.View(req, res),
        locals = res.locals;
    
    // locals.section is used to set the currently selected
    // item in the header navigation.
    locals.section = 'home';
    
    // Render the view
    view.query('Rekrys', keystone.list('Rekrys').model.find());
    view.render('rekry');
    
    };