How to change the title of a document in Sanity's structure builder and how to make a schema type a singleton.
7 replies
Last updated: May 13, 2020
S
How do I in structure builder change the title of the document that is selected seen in this image
S
This is my structure so far
S
import S from "@sanity/desk-tool/structure-builder";
export default () =>
// Make a new list item
S.list()
.title("Content")
.items([
S.listItem()
.title("KM Posts")
// This automatically gives it properties from the project type
.schemaType("twentyTwentyKmPost")
// When you open this list item, list out the documents
// of the type "project"
.child(S.documentTypeList("twentyTwentyKmPost").title("2020-2021")),
S.listItem()
.title("KT Posts")
// This automatically gives it properties from the project type
.schemaType("twentyTwentyKtPost")
// When you open this list item, list out the documents
// of the type "project"
.child(S.documentTypeList("twentyTwentyKtPost").title("2020-2021")),
S.listItem()
.title("Slide Deck")
// This automatically gives it properties from the project type
.schemaType("slideDeck")
// When you open this list item, list out the documents
// of the type "project"
.child(S.documentTypeList("slideDeck").title("Cards")),
S.listItem()
.title("Curriculum")
// This automatically gives it properties from the project type
.schemaType("curriculumPost")
// When you open this list item, list out the documents
// of the type "project"
.child(S.documentTypeList("curriculumPost").title("Content")),
S.listItem()
// Give it a title
.title("Archives")
.child(
// Make a list in the second pane called Portfolio
S.list()
.title("2010-2017")
.items([
// Add the first list item
S.listItem()
.title("2010 - 2011")
// This automatically gives it properties from the project type
.schemaType("twentyTenPost")
// When you open this list item, list out the documents
// of the type "project"
.child(S.documentTypeList("twentyTenPost").title("Posts")),
// Add a second list item
S.listItem()
.title("2011 - 2012")
.schemaType("twentyElevenPost")
// When you open this list item, list out the documents
// of the type category"
.child(S.documentTypeList("twentyElevenPost").title("Posts")),
S.listItem()
.title("2012 - 2013")
.schemaType("twentyThirteenPost")
// When you open this list item, list out the documents
// of the type category"
.child(S.documentTypeList("twentyThirteenPost").title("Posts")),
S.listItem()
.title("2014 - 2015")
.schemaType("twentyFourteenPost")
// When you open this list item, list out the documents
// of the type category"
.child(S.documentTypeList("twentyFourteenPost").title("Posts")),
S.listItem()
.title("2015 - 2016")
.schemaType("twentyFifteenPost")
// When you open this list item, list out the documents
// of the type category"
.child(S.documentTypeList("twentyFifteenPost").title("Posts")),
S.listItem()
.title("2016 - 2017")
.schemaType("twentySixteenPost")
// When you open this list item, list out the documents
// of the type category"
.child(S.documentTypeList("twentySixteenPost").title("Posts")),
S.listItem()
.title("2018 - 2019 KT")
.schemaType("twentyEighteenKtPost")
// When you open this list item, list out the documents
// of the type category"
.child(
S.documentTypeList("twentyEighteenKtPost").title("Posts")
),
S.listItem()
.title("2018 - 2019 KM")
.schemaType("twentyEighteenKmPost")
// When you open this list item, list out the documents
// of the type category"
.child(
S.documentTypeList("twentyEighteenKmPost").title("Posts")
),
S.listItem()
.title("2019 - 2020 KT")
.schemaType("twentyNineteenKtPost")
// When you open this list item, list out the documents
// of the type category"
.child(
S.documentTypeList("twentyNineteenKtPost").title("Posts")
),
S.listItem()
.title("2019 - 2020 KM")
.schemaType("twentyNineteenKmPost")
// When you open this list item, list out the documents
// of the type category"
.child(
S.documentTypeList("twentyNineteenKmPost").title("Posts")
),
])
),
]);S
Also how would I make curriculumPost a singleton
S
I changed it to a singleton with
and added this below
but now the content from curriculum post is empty, it's like the filter is also taking away the content.
S.listItem()
.title("Curriculum Content")
.child(
S.document().schemaType("curriculumPost").documentId("curriculumPost")
),...S.documentTypeListItems().filter(
(listItem) =>
![
"curriculumPost",
"slideDeck",
"twentyEighteenKtPost",
"twentyEighteenKmPost",
"twentyTenPost",
"twentyElevenPost",
"twentyTwelvePost",
"twentyThirteenPost",
"twentyFourteenPost",
"twentyFifteenPost",
"twentySixteenPost",
"twentySeventeenKtPost",
"twentySeventeenKmPost",
"twentyNineteenKmPost",
"twentyNineteenKtPost",
"twentyTwentyKmPost",
"twentyTwentyKtPost",
].includes(listItem.getId())
),A
I changed it to a singleton with
and added this below
but now the content from curriculum post is empty, it's like the filter is also taking away the content.
S.listItem()
.title("Curriculum Content")
.child(
S.document().schemaType("curriculumPost").documentId("curriculumPost")
),...S.documentTypeListItems().filter(
(listItem) =>
![
"curriculumPost",
"slideDeck",
"twentyEighteenKtPost",
"twentyEighteenKmPost",
"twentyTenPost",
"twentyElevenPost",
"twentyTwelvePost",
"twentyThirteenPost",
"twentyFourteenPost",
"twentyFifteenPost",
"twentySixteenPost",
"twentySeventeenKtPost",
"twentySeventeenKmPost",
"twentyNineteenKmPost",
"twentyNineteenKtPost",
"twentyTwentyKmPost",
"twentyTwentyKtPost",
].includes(listItem.getId())
),P
Hi Anders, for the singleton, assuming you would like to open it directly in an editor/form view, have you tried something like this?
Also, have you confirmed that the singleton document itself actually has a document
S.listItem()
.title('Curriculum Content')
.child(
S.editor()
.title('Curriculum Content')
.schemaType('curriculumPost')
.documentId('curriculumPost')
),_idof
curriculumPost? And not some random string?
A
I got it working, I think sanity was having a bug with having two posts in the singleton, I delete both of them just created one and then it acted as needed. I will also try your suggestion to see how that looks thanks
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.