Fields

Boolean

A yes or no value, shown as a checkbox or a switch.
The boolean field in the admin

Example

cms/collections/posts.ts
export const posts = defineCollection({
  fields: {
    featured: { type: "boolean", label: "Show on the home page" },
    comments: { type: "boolean", appearance: "switch", default: true },
  },
});

A read returns true or false. An optional boolean can also be null or missing, so treat those as false:

const featured = await cms.find("posts", { where: { featured: true } });

Render it

<article class:list={["post", { featured: post.featured }]}>
  {post.featured && <span class="badge">Featured</span>}
  <h2>{post.title}</h2>
</article>

A boolean is often the switch for a condition:

forSale: { type: "boolean" },
price: { type: "number", condition: { forSale: true } },

Switch

appearance: "switch" shows a toggle instead of a checkbox:

The boolean-switch field in the admin

Options

The input in the admin. Default "checkbox".