Issue with parent/child taxonomy template in Sanity Studio v3
6 replies
Last updated: Jun 2, 2024
E
Hi all!I’ve been following User’s “Creating a Parent/Child Taxonomy” guide, up until the Pre-flight check section. I’ve copied the files exactly, yet when I try to access the documents I’ve created from the initial “All” folder, I get this error message:
Structure path
Error
I can access the documents if I go via one of the sub folders, which implies that the issue should be located at the bottom of the parentChild.ts file, here:
)`
I can't seem to find the error, everything looks fine to me. Has anyone else experienced this same issue? All help is greatly appreciated
🙏
Structure path
all26fc9c11-e7c1-42d6-92b8-d1b94cc3ce88category-child
template id (`templateId`) is required for initial value template item nodes
I can access the documents if I go via one of the sub folders, which implies that the issue should be located at the bottom of the parentChild.ts file, here:
child: () =>
S.documentTypeList(schemaType)
.title('Children')`.filter(
_type == $schemaType && parent._ref == $parentId
.params({ schemaType, parentId: parent._id })
// Use this list for creating from child menu
.canHandleIntent((intentName, params) => intentName === 'create' && params.template === 'category-child')
.initialValueTemplates([
S.initialValueTemplateItem('category-child', {
parentId: parent._id,
}),
]),
I can't seem to find the error, everything looks fine to me. Has anyone else experienced this same issue? All help is greatly appreciated
🙏
May 31, 2024, 3:18 PM
E
For fun, I tried replacing initialValueTemplates with , which produces a slightly different error msg:
Could it be that the structure builder is run before the templates function inside sanity.config.ts? Seems weird, tho...
.child(S.documentWithInitialValueTemplate('category-child', { parentId: parent._id })),
Error: Template with ID "category-child" not defined
Could it be that the structure builder is run before the templates function inside sanity.config.ts? Seems weird, tho...
May 31, 2024, 3:25 PM
Oh wait, actually, have you defined the template, like so:
// ./sanity.config.ts import {defineConfig} from 'sanity' import {schemaTypes} from './schemas' export default defineConfig({ // ...all other settings schema: { // All your schema types types: schemaTypes, // Add this 'category child' template templates: (prev) => { const categoryChild = { id: 'category-child', title: 'Category: Child', schemaType: 'category', parameters: [{name: `parentId`, title: `Parent ID`, type: `string`}], // This value will be passed-in from desk structure value: ({parentId}: {parentId: string}) => ({ parent: {_type: 'reference', _ref: parentId}, }), } return [...prev, categoryChild] }, },
May 31, 2024, 5:25 PM
E
That's a good guess as to why it wouldn't have worked, but I have indeed added the template.
May 31, 2024, 8:16 PM
E
And it's v3 of the studio, the project was started no more than a month ago.
May 31, 2024, 8:18 PM
E
I just realized what I did, a silly little mistake. I placed the templates outside of the schema object in sanity.config.ts 😛
Jun 2, 2024, 8:27 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.