Trouble passing environment variables in Sanity Studio

3 replies
Last updated: Apr 29, 2020
I could like to conditionally render items in the deskStructure based on environment. Have been referring to the doc’s
<https://www.sanity.io/docs/studio-environment-variables>
but for whatever reason I can’t get my
.env
or
.env.development
variables to pass through? Hoping to do something like the following:
const dataset = process.env.SANITY_STUDIO_API_DATASET

export default () =&gt; {
  if(dataset == "staging"){
    S.list()
      .title('Content')
      .items([
        S.listItem()
          .title('Home Page')
          .schemaType('homePage')
          .child(S.document().schemaType('homePage')),
am I going about this the correct way?
Apr 29, 2020, 8:44 PM
Better to do it like this:
import client from “part:@sanity/base/client”

const { dataset } = client.config()
Apr 29, 2020, 8:49 PM
Better to do it like this:
import client from “part:@sanity/base/client”

const { dataset } = client.config()
Apr 29, 2020, 8:49 PM
thanks
Knut Melvær
, appreciate it! 🌟
Apr 29, 2020, 8:51 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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?