👀 See Sanity in action: Watch product demo now →

Is there a way to Conditionally include a `listItem` in the Desk Structure?

5 replies
Last updated: Jun 6, 2020
This might be trivial… but is there a way to conditionally include a
listItem
in the desk structure?
Something like…

// if (var === true) {
S.listItem()
        .title('Pages')
        .icon(IoIosDocument)
        .child(S.documentTypeList('page').title('Pages')),
\\ }
Jun 5, 2020, 6:46 PM
Key
user F
. Try this
...( var === true ? [
  S.listItem()
    .title('Pages')
    .icon(IoIosDocument)
    .child(S.documentTypeList('page').title('Pages')),
] : [] ),
Jun 5, 2020, 7:25 PM
You’re a good man Charlie Brown! Worked like dang charm!!
Jun 5, 2020, 7:31 PM
user F
what is your use case for this?
Jun 5, 2020, 8:15 PM
user T
I reuse a Sanity/Gatsby install with “modules”, and manage both with a single config.js file. Its still very much a work in progress, but it works pretty well.
So for this specifically. In the config file I have something like

{
  staffModule: {
    activated: true
  }
}
and I use that to dictate if it shows in the Sanity Desk as well as if Gatsby builds out those pages.
Jun 6, 2020, 2:13 PM
Interesting, thank you for sharing 👍
Jun 6, 2020, 2:15 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.