Restrict Kentico Content in Edit Mode

Restrict Kentico Content in Edit Mode

While in Kentico Edit Mode you might want to hide or not load certain content or scripts which slows the editing process and only necessary for live mode.

This trick would not care what page layout type you’re using (ASCX or HTML).

On the Master Page, create a new Zone for the content you would like to hide.
This way any widgets/webparts added under this zone will not load while in edit mode:

<cms:CMSWebPartZone ZoneID="ZoneScripts" runat="server" />

Or, you can just reuse one of the zones you already have and just have the widget/webpart restrict the content in edit mode (see next).

Next, add a widget/webpart to your zone and under Visibility or Behavior click the small arrow next to Visible or Enabled and add the following macro code and hit save:

{% PortalContext.ViewMode == "LiveSite" #%}

restrict kentico content in edit mode
restrict kentico content in edit mode
restrict kentico content in edit mode
restrict kentico content in edit mode

Also, here’s how to hide content while in edit mode on the Master Page.
For example, I wanted to hide the Google Tag Manager code:

{% if(ViewMode == "LiveSite"){ %}
Your Content to hide in Edit Mode goes here.
{% } #%}

restrict kentico content in edit mode