Take the community feedback survey now.

Rajveer Singh
Jul 1, 2025
  500
(3 votes)

Environment-specific badges in the Optimizely CMS

Step 1: Add Environment Info to the UI

Create a custom UIDescriptor and a ComponentDefinition to inject a badge into the CMS UI.

using EPiServer.Shell;
using EPiServer.Shell.ViewComposition;

[UIDescriptorRegistration]
public class EnvironmentBadgeUIDescriptor : UIDescriptor
{
    public EnvironmentBadgeUIDescriptor()
        : base("environment-badge")
    {
        DisabledViews = new string[] { };
    }
}

 

Step 2: Add a Client Resource

Create a JavaScript file that will render the badge in the CMS UI.

define([
    "dojo/_base/declare",
    "epi/_Module",
    "dojo/dom-construct",
    "dojo/domReady!"
], function (declare, _Module, domConstruct) {
    return declare([_Module], {
        initialize: function () {
            this.inherited(arguments);

            var env = window.cmsEnvironment || "Production";
            var color = {
                Development: "#007bff",
                Staging: "#ffc107",
                Production: "#28a745"
            }[env] || "#6c757d";

            var badge = domConstruct.create("div", {
                innerHTML: env,
                style: `
                    position: fixed;
                    top: 10px;
                    right: 10px;
                    background-color: ${color};
                    color: white;
                    padding: 5px 10px;
                    font-weight: bold;
                    border-radius: 4px;
                    z-index: 9999;
                `
            }, document.body);
        }
    });
});

 

Step 3: Register the Module in module.config

<module>
  <clientModule initializer="environment-badge">
    <requiredResources>
      <add name="epi.shell" />
    </requiredResources>
  </clientModule>
</module>

 

Step 4: Set the Environment in Razor or Layout

In your _Layout.cshtml or a shared Razor view:

<script>
    window.cmsEnvironment = '@Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")';
</script>

 

 

When editors log into the CMS, they’ll see a badge in the top-right corner showing the current environment, color-coded for clarity.

 

Jul 01, 2025

Comments

huseyinerdinc
huseyinerdinc Jul 2, 2025 07:16 AM

Nice idea. Would you mind posting a screenshot of the result?

Rajveer Singh
Rajveer Singh Jul 2, 2025 07:22 AM

Updated the screen shot what we achieved.

Eric Markson
Eric Markson Jul 8, 2025 01:38 PM

The image looks broken. Can you please try and upload it again

Please login to comment.
Latest blogs
Building Faster Feedback Loops with Opal: Two Hackathon Projects

Two Opal Hackathon projects explored how to bridge data and action. Using the Optimizely.Opal.Tools SDK, we extended Opal with new tools, showing h...

Andy Blyth | Sep 3, 2025 |

Custom Deepl Glossary Translation in Optimizely CMS

Introduction in this post, I have created a custom DeepL glossary translation for specific words. For example, when translating from English to...

Deepmala S | Sep 3, 2025

Showing Unpublished Block Status in Optimizely CMS 12 ContentArea

Introduction One of the most common editor complaints in Optimizely CMS is that it’s not obvious when a block inside a ContentArea has unpublished...

Adnan Zameer | Sep 2, 2025 |

How to Show Unpublished Blocks in Page Preview (Optimizely CMS 12)

Introduction In this post, we’ll look at why Draft Blocks don’t show in Page Preview by default, and I'll show you a clean, drop-in solution to fix...

Adnan Zameer | Sep 1, 2025 |

A day in the life of an Optimizely Developer - We Hacked the Future: Netcel's Opal Hackathon Adventure

Ever wondered what happens when you mix  AI ,  creativity , and a dash of competitive spirit? Welcome to the  Opal Hackathon 2025 —where we rolled ...

Graham Carr | Aug 31, 2025

Simple Feature Flags In Optimizely CMS

The Problem I was working with a CMS 11 client who wanted to introduce two new third party content sources. These would be synchronized into new...

Mark Stott | Aug 31, 2025