where are mdx fields allowed (in addition to contentField)?
#995
-
|
hi, i am playing with the new mdx field, and was wondering where mdx fields are allowed in a collection schema. for example, with the following config,
import { config, collection, fields } from "@keystatic/core";
import { block } from "@keystatic/core/content-components";
export default config({
storage: { kind: "local" },
collections: {
posts: collection({
label: "Posts",
slugField: "title",
path: "posts/*/",
format: { contentField: "content" },
schema: {
title: fields.slug({ name: { label: "Title" } }),
/** This field will be saved as a separate.mdx file. */
summary: fields.mdx({ label: "Summary" }),
/** This field will be saved as the body of index.mdx. */
content: fields.mdx({
label: "Content",
components: {
Quiz: block({
label: "Quiz",
schema: {
/** This field cannot be an mdx field. */
question: fields.text({ label: "Question", multiline: true }),
/** This field cannot be an mdx field. */
answers: fields.array(fields.text({ label: "Answer", multiline: true }), {
label: "Answers",
}),
},
}),
},
}),
},
}),
},
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Hey! So — it's not likely that having a MDX field inside another MDX field is going to be possible. However, if you use a So in your example, the Then, you'd create an Hopefully that approach makes sense! UPDATE: I made a little demo in StackBlitz. Lines 18 - 35 of the |
Beta Was this translation helpful? Give feedback.


Hey!
So — it's not likely that having a MDX field inside another MDX field is going to be possible. However, if you use a
wrappercontent component, you have access to freeform Markdown + blocks inside that field. Paired with arepeatingcomponent, you could achieve what you want nicely.So in your example, the
Quizzcomponent could be turned into arepeatingcomponent instead ofblock. Thequestionwould be part of the schema for therepeatingcomponent, and for thechildrenarray you'd allow theAnswercomponent.Then, you'd create an
Answercomponent which is awrappercomponent, with an empty schema. You can write the answer with MDX inside the wrapper component, and add as many answe…