Help needed to learn how to create Sanity Tree structure content for a Next.js app.
10 replies
Last updated: Oct 6, 2023
A
👋 Hello, team! I want to learn to create Sanity Tree structure content for my nextjs app, but I cannot find any useful resources to learn it. If possible, please help me find useful resources to learn it
Oct 5, 2023, 4:13 PM
👋 Here ya go!
Oct 5, 2023, 5:38 PM
A
hey
user M
, I want to create this type of structure with sanity. I have read this documentation(https://www.sanity.io/guides/hierarchies-graphs-navigation ), but it does not of that much help. I'm new to sanity, if possible, please let me know if there is a better way to do it.Oct 6, 2023, 5:52 AM
A
any library or blog showing about how can I create above structure might help.
Oct 6, 2023, 5:53 AM
A
this is my current schema for roadmap.ts file:
const roadmap = {
name: 'roadmap',
title: 'Roadmap',
type: 'document',
fields: [
defineField({
name: "title",
title: "Title",
type: "string",
description: "Write Roadmap title.",
validation: (rule) => rule.required()
}),
defineField({
name: 'checkpoints',
title: 'Checkpoints',
type: 'array',
of: [{ type: 'reference', to: { type: 'checkpoint' } }], // Reference to the same "checkpoint" type
}),
]
}
export default roadmap;
import { defineField } from 'sanity';
const roadmap = {
name: 'roadmap',
title: 'Roadmap',
type: 'document',
fields: [
defineField({
name: "title",
title: "Title",
type: "string",
description: "Write Roadmap title.",
validation: (rule) => rule.required()
}),
defineField({
name: 'checkpoints',
title: 'Checkpoints',
type: 'array',
of: [{ type: 'reference', to: { type: 'checkpoint' } }], // Reference to the same "checkpoint" type
}),
]
}
export default roadmap;
Oct 6, 2023, 5:54 AM
A
This is my current schema for roadmap.ts file:
Oct 6, 2023, 5:54 AM
A
This is my current schema for roadmap.ts file:
And this is checkpoint.ts file:
I'm able to create single children but not multiple children for the same parent.
import { defineField } from 'sanity';
const roadmap = {
name: 'roadmap',
title: 'Roadmap',
type: 'document',
fields: [
defineField({
name: "title",
title: "Title",
type: "string",
description: "Write Roadmap title.",
validation: (rule) => rule.required()
}),
defineField({
name: 'checkpoints',
title: 'Checkpoints',
type: 'array',
of: [{ type: 'reference', to: { type: 'checkpoint' } }], // Reference to the same "checkpoint" type
}),
]
}
export default roadmap;
And this is checkpoint.ts file:
import { defineField } from 'sanity';
const checkpoint = {
name: 'checkpoint',
title: 'Checkpoint',
type: 'document',
fields: [
defineField({
name: "title",
title: "Title",
type: "string",
description: "Write checkpoint title.",
validation: (rule) => rule.required()
}),
]
}
export default checkpoint;
I'm able to create single children but not multiple children for the same parent.
Oct 6, 2023, 5:56 AM
A
yes, but it doesn't help that much.
Oct 6, 2023, 4:24 PM
It tells you how to do exactly what you’re looking for, so I’d say spend some time trying to understand and apply it.
Oct 6, 2023, 4:25 PM
A
ok, it works now. Thanks for the help!
Oct 6, 2023, 4:33 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.