Content Types in Code
You create a content type in Visor, with no code. See Content Types, or ask a connected AI tool. It then appears in the menu with its workflow, permissions and scope set up for you, so editors can use it straight away.
Code is needed only to show it on the website.
What a content type is called
Visor generates the technical name from the display name and the site.
| Kind | Technical name | In code |
|---|---|---|
| With workflow | xtr_cms_data_news_a1b2c3 | xtr_cms_data_news |
| Simple data | xtr_cms_simple_links_a1b2c3 | xtr_cms_simple_links |
| Shared with all sites | xtr_cms_data_news | xtr_cms_data_news |
a1b2c3 is the site’s key. Use the name without the key. lib/daas.ts adds it for you, so your code works on any site.
Show items in a widget
There’s no general widget for listing any content type, so you create a site widget for each one. The create-widget and daas-api-patterns skills know these patterns.
Read the items
On the server, use readItems:
import { readItems } from "@/lib/daas";
const rows = await readItems("xtr_cms_data_news_translations", {
filter: {
status: { _eq: "Published" },
language_code: { _eq: languageId },
xtr_cms_data_news_id: { _nnull: true },
},
fields: ["title", "slug", "summary", "image"],
sort: ["-date_created"],
limit: 6,
});Read them in the client variant
Browser code can’t call GoDaaS, so the client variant calls POST /api/data-sources instead.
Build the links
Use buildDataHref, buildDataHierarchy or attachDataResolvedHrefs, instead of writing paths by hand.
Rules
| Kind | What to know |
|---|---|
| Translated type | Read the _translations collection. Filter on status, which is the exact string Published, and on language_code, which is the language’s ID. Require the parent link to be non-null. |
| Child list | The child’s link column, such as trip_id, holds the parent’s default-language translation ID. |
| Simple data | It has no title, slug or status. Use your own fields. |
Pages read published content only, including under npm run dev, so a new item appears once it’s published.
An item’s own page
Each item of a workflow type gets its own page under /articles/, whatever the type is called. A translated item in another language is under /<code>/articles/.
/articles/<parents>/<slug>
/id/articles/<parents>/<slug>An item appears only once it and all its parents have a published translation. Simple data has no pages of its own, so show it with a widget.
To choose how these pages look, set the type’s layout in Content Type Layouts, or use visor_type_layout_set. The VdsArticleLayout layout includes a rich text widget that shows the item’s own text.
Your own route
You can add a route such as app/events/[...slug]/, which is one of your site’s places. Be aware of two things:
- The build’s page-switching script handles only the template’s own routes, so your route’s
page.tsxruns as it is in every mode. - In the live build it needs its own
generateStaticParams.
Test yours in both modes. See Rendering modes.
Hard to undo
Once pages, widgets or the site’s code use a type, renaming or removing it breaks them. Agree the types with your team before you build on them.