A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Rajveer Singh
Jul 1, 2025
  725
(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 simple Opal tools for product search and content creation

Optimizely Opal tools make it easy for AI agents to call your APIs – in this post we’ll build a small ASP.NET host that exposes two of them: one fo...

Pär Wissmark | Dec 13, 2025 |

CMS Audiences - check all usage

Sometimes you want to check if an Audience from your CMS (former Visitor Group) has been used by which page(and which version of that page) Then yo...

Tuan Anh Hoang | Dec 12, 2025

Data Imports in Optimizely: Part 2 - Query data efficiently

One of the more time consuming parts of an import is looking up data to update. Naively, it is possible to use the PageCriteriaQueryService to quer...

Matt FitzGerald-Chamberlain | Dec 11, 2025 |

Beginner's Guide for Optimizely Backend Developers

Developing with Optimizely (formerly Episerver) requires more than just technical know‑how. It’s about respecting the editor’s perspective, ensurin...

MilosR | Dec 10, 2025