Development of Custom Collections and Singletons in Cockpit CMS
Collections and Singletons are the two main types of content in Cockpit. Collections are for repeating entries (articles, products), Singletons are for unique sets of fields (homepage settings, about page).
Creating a Collection via API
// Cockpit allows creating collections through Admin UI or programmatically
// POST /api/collections/createCollection
$collection = [
'name' => 'products',
'label' => 'Products',
'fields' => [
['name' => 'title', 'type' => 'text', 'required' => true, 'label' => 'Title'],
['name' => 'slug', 'type' => 'text', 'required' => true, 'slug' => true],
['name' => 'description', 'type' => 'wysiwyg', 'label' => 'Description'],
['name' => 'price', 'type' => 'number', 'label' => 'Price'],
['name' => 'image', 'type' => 'asset', 'label' => 'Photo'],
['name' => 'gallery', 'type' => 'gallery', 'label' => 'Gallery'],
['name' => 'category', 'type' => 'collectionlink', 'link' => 'categories'],
['name' => 'published', 'type' => 'boolean', 'default' => false],
['name' => 'publishedAt', 'type' => 'date'],
],
'sortable' => true,
'in_menu' => true,
];
Cockpit Field Types
| Type | Description |
|---|---|
text |
String |
textarea |
Multiline text |
wysiwyg |
Rich text editor |
markdown |
Markdown |
number |
Number |
boolean |
Toggle switch |
select |
Dropdown list |
asset |
File/image |
gallery |
Image gallery |
date / time |
Date/time |
color |
Color picker |
collectionlink |
Link to another collection entry |
repeater |
Repeating field groups |
layout |
Block builder |
object |
JSON object |
tags |
Tags (array of strings) |
set |
Field group |
Singleton
A Singleton differs from a Collection in that it stores a single set of values:
// Singleton "homepage" structure
{
"fields": [
{ "name": "hero_title", "type": "text" },
{ "name": "hero_subtitle", "type": "textarea" },
{ "name": "hero_image", "type": "asset" },
{ "name": "featured_posts", "type": "collectionlink", "link": "posts", "multiple": true },
{ "name": "seo_title", "type": "text" },
{ "name": "seo_description", "type": "textarea" }
]
}
Using Repeater for Content Blocks
Repeater allows the editor to add any number of identical blocks:
{
"name": "features",
"type": "repeater",
"label": "Features",
"fields": [
{ "name": "icon", "type": "asset" },
{ "name": "title", "type": "text" },
{ "name": "description", "type": "textarea" }
]
}
Setting up 3–5 collections with typical fields and relationships takes 4–8 hours.







