Using environment variable in Smart View

Expected behavior

Our iFrame URL in Smart View could use a value from environment variable.

Actual behavior

We’re using iFrame URL in Smart View with hard code string. However, the iFrame URL is different between environments like production or staging. We don’t want to make a mistake when copy layout settings from Staging to Production but forget to update the iFrame URL value corresponding.

Hi @mr.leo,

I don’t think Forest Admin provides a way to expose “environment variables” in your project settings to make them available from Smart View implementation.

I see 2 workaround to handle your use case:

  • declare a hash in your Smart View to map the environment to the expected iFrame URL,
  • declare an environment variable in your Admin API backend and find a way to make the Smart View request this information on load/display.

Let me know if it helps.


Thanks for your reply,

Actually our solution is similar to your option 2. We store value into our database and load it as Smart Field then inject into Smart UI.

For option 1, it would be great if you elaborate it by example.

About the option 1, you could define, in your component.js, a hash like this:

const mapping = {
  development: 'my-development-url',
  staging: 'my-staging-url',
  qa: 'my-qa-url',
  production: 'my-production-url',

and then, in the same component.js, create a computed property that would return the right url with this logic:

return mapping[];

This is new to me. Does Forestadmin support to get the current environment name like this? Couldn’t find it in document.

yes it should.
it does the same thing as collection.get('') with a newer/lighter syntax.

Thanks. It’ll be helpful for us in someway.