👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

How to Fetch a Value in the Structurebuilder from a Page

1 replies
Last updated: Nov 1, 2021
I need to fetch a value in my Structurebuilder from a page. In this case, it’s which language the page has instead of having “en” as fixed, it should get the “language” value from that page. How would I go about doing it in this case? Is it possible to ad a GROQ query or something in
S.view.options
? The only value I can get from the `S.document()`seems to be the documentId, maybe somehow fetch the value dynamically using that ID?
export const getDefaultDocumentNode = (props) => {
  if (props.schemaType === "page") {
    return S.document().views([
      S.view.form().icon(FaEdit).title("Edit"),
      S.view
        .component(IframePreview)
        .options({ previewURL, selectedLanguage: "en" })
        .title("Preview")
        .icon(FaEye),
    ]);
  }
};
Oct 26, 2021, 11:17 AM
You can access information in the document inside of your
S.view.component
by using
document.displayed.<field>
. You could try passing that value to your 'selectedLanguage' option.
Nov 1, 2021, 8:25 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.

Was this answer helpful?