Mike Skutta Blog

Sitecore How-To: Conditionally Render HTML Based on Configuration (Razor) Site

George West and Mike Skutta


This is an article in a series of Sitecore how-to articles. These articles are meant to be quick guides to accomplish various tasks within Sitecore. The how-to articles have proven to be very helpful internally at One North Interactive https://www.onenorth.com. These articles assume working Sitecore knowledge. I just wanted to share the articles with the community. Hopefully you find them helpful.


This article explains how to change your output markup of your Sitecore site according to its configuration.

Sometimes, you may want to render something differently in development versus production.

A good example of this is scripts loaded via CDN. Vue, for example:

Turn on Production Mode

During development, Vue provides a lot of warnings to help you with common errors and pitfalls. However, these warning strings become useless in production and bloat your app’s payload size. In addition, some of these warning checks have small runtime costs that can be avoided in production mode.

Step-by-step guide

To do this, we can define and use an HtmlHelper extension method which checks the Sitecore configuration for a feature-specific (in this case, HTML rendering) value.


<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
      <setting name="OneNorth.HtmlEnvironment" value="dev"/>


using System.Web.Mvc;
public static class HtmlHelperExtensions
    public static bool IsDebug(this HtmlHelper htmlHelper)
        return Sitecore.Configuration.Settings.GetSetting("OneNorth.HtmlEnvironment") == "dev";


@if (Html.IsDebug())
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
} else
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>

Similar Posts