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 4 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
wrapper
content component, you have access to freeform Markdown + blocks inside that field. Paired with arepeating
component, you could achieve what you want nicely.So in your example, the
Quizz
component could be turned into arepeating
component instead ofblock
. Thequestion
would be part of the schema for therepeating
component, and for thechildren
array you'd allow theAnswer
component.Then, you'd create an
Answer
component which is awrapper
component, with an empty schema. You can write the answer with MDX inside the wrapper component, and add as many answe…