Skip to content

Instantly share code, notes, and snippets.

@charleslouis
Created December 1, 2015 15:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charleslouis/ff5cc15ce7d2f3aee59d to your computer and use it in GitHub Desktop.
Save charleslouis/ff5cc15ce7d2f3aee59d to your computer and use it in GitHub Desktop.
keystone-Page.js model page model
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* Page Model
* ==========
*/
var Page = new keystone.List('Page', {
map: { name: 'title' },
autokey: { path: 'slug', from: 'title', unique: true }
});
Page.add({
title: { type: String, required: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true },
author: { type: Types.Relationship, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
//create a dropdown with templates
template: { type: Types.Select, options: 'page, about, team, contact, portfolio', default: 'page'},
image: { type: Types.CloudinaryImage },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 }
},
//Display someField if the selected template is 'about'
someField: { type: String, dependsOn: { template: 'about' } },
});
Page.schema.virtual('content.full').get(function() {
return this.content.extended || this.content.brief;
});
Page.defaultColumns = 'title, state|20%, author|20%, publishedDate|20%';
Page.register();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment