Skip to content

Collections

Collections in Lucid allow you to define a type content. Within these collections exist documents. A collection can either contain multiple, or just a single document depending on the mode flag. Collections give you the flexibility to add fields, builder bricks and fixed bricks against them. The custom fields these contain will then be available on the document page builder.

Example

collections.ts
import { CollectionBuilder } from "@lucidcms/core/builders";
import Banner from "./bricks/banner.js";
import SEO from "./bricks/seo.js";
export const PageCollection = new CollectionBuilder("page", {
mode: "multiple",
title: "Pages",
singular: "Page",
description: "Pages are used to create static content on your website.",
translations: true,
hooks: [
{
event: "beforeUpsert",
handler: async (props) => {},
},
],
bricks: {
fixed: [SEO],
builder: [Banner],
},
})
.addText(
"pageTitle",
{
labels: {
title: {
en: "Page title",
},
description: "The title of the page.",
},
hidden: false,
disabled: false,
},
{
list: true,
filterable: true,
}
)
.addTextarea("pageExcerpt", undefined, {
list: true,
filterable: true,
})
.addCheckbox(
"pageFeatured",
{
translations: true,
},
{
list: true,
filterable: true,
}
)
.addUser("author", undefined, {
list: true,
});
export const SettingsCollection = new CollectionBuilder("settings", {
mode: "single",
title: "Settings",
singular: "Setting",
description: "Set shared settings for your website.",
translations: false,
bricks: {
fixed: [],
builder: [],
},
}).addMedia("siteLogo", {
labels: {
title: "Logo",
},
});