Generate Momentum CMS Collection
Create a new collection file following project conventions.
Arguments
$ARGUMENTS- Collection name (e.g., "posts", "products", "users")
Important: Collection Location
All collections are defined in libs/example-config/src/collections/. Both example apps (example-angular, example-analog) import from @momentumcms/example-config/collections. Never define collections in individual apps.
Steps
-
Create the collection file at
libs/example-config/src/collections/<name>.collection.ts -
Use this template:
typescript1import { 2 defineCollection, 3 text, 4 richText, 5 number, 6 date, 7 checkbox, 8 select, 9 relationship, 10} from '@momentumcms/core'; 11 12export const <PascalName> = defineCollection({ 13 slug: '<kebab-name>', 14 15 admin: { 16 useAsTitle: 'title', // or 'name' - the field to display as title 17 defaultColumns: ['title', 'createdAt'], 18 group: 'Content', // Admin sidebar group 19 }, 20 21 access: { 22 read: () => true, 23 create: ({ req }) => !!req.user, 24 update: ({ req }) => req.user?.role === 'admin', 25 delete: ({ req }) => req.user?.role === 'admin', 26 }, 27 28 hooks: { 29 beforeChange: [], 30 afterChange: [], 31 }, 32 33 fields: [ 34 text('title', { required: true }), 35 // Add more fields as needed 36 ], 37});
- Export from
libs/example-config/src/collections/index.ts:
typescript1// Add import at top 2import { <PascalName> } from './<name>.collection'; 3 4// Add to the collections array 5export const collections: CollectionConfig[] = [ 6 // ... existing collections, 7 <PascalName>, 8]; 9 10// Add to named exports 11export { 12 // ... existing exports, 13 <PascalName>, 14};
Both example apps automatically pick up changes since they import from @momentumcms/example-config/collections.
- Remind user: if migration mode is enabled, run
nx run <app>:migrate:generateafter collection changes to create a migration file.
Field Types Available
Text Input Fields
text(name, options)- Short text with optional min/max lengthtextarea(name, options)- Multi-line text with optional rowsrichText(name, options)- Rich text editoremail(name, options)- Email inputpassword(name, options)- Password input with optional min length
Numeric & Date Fields
number(name, options)- Numeric value with optional min/max/stepdate(name, options)- Date/datetime picker
Boolean & Selection Fields
checkbox(name, options)- Boolean checkboxselect(name, { options: [...] })- Dropdown select (supportshasMany)radio(name, { options: [...] })- Radio button group
Media & Files
upload(name, options)- File upload with MIME type filtering
Relationship & Data Fields
relationship(name, { collection: () => Ref })- Reference to another collection (supportshasMany, polymorphic)array(name, { fields: [...] })- Array of nested fieldsgroup(name, { fields: [...] })- Nested object groupingblocks(name, { blocks: [...] })- Block-based contentjson(name, options)- Raw JSON fieldpoint(name, options)- Geolocation pointslug(name, { from: 'fieldName' })- Auto-generated slug from another field
Layout Fields (non-data storing)
tabs(tabs: [...])- Tabbed sections for organizationcollapsible(label, { fields: [...] })- Collapsible sectionrow(fields: [...])- Horizontal row layout