detect if we are in design mode inside page layout

benyamin jain asked on November 14, 2015 10:40

Hi

In Kentico cms 7.0 how it is possible to detect if are in degin mode or edit mode?

i need this inside Page template layout properties.

for example :

<% if(IsDesingMode){ %>
somthing goes here...
<% }  %>

is there anything like this in kentico API?

Thank you

Correct Answer

David te Kloese answered on November 14, 2015 14:56

Hi,

I've used this before on a template that had multiple places that needed this.

Place the following code to make the boolean available:

<script runat="server">
    protected bool IsCmsDesk() {
      return !Equals(CMSContext.ViewMode, CMS.PortalEngine.ViewModeEnum.LiveSite) 
        && !Equals(CMSContext.ViewMode, CMS.PortalEngine.ViewModeEnum.Preview);
    }
</script>

In your template you can use the following:

<% if(IsCmsDesk()) { %>

some html...

<% } %>

Greets,

David

2 votesVote for this answer Unmark Correct answer

Recent Answers


Jan Hermann answered on November 16, 2015 08:52

Hello,

Or you can switch your layout type to HTML and use just following code:

{% if (PortalContext.ViewMode != "LiveSite") { %}

HTML

{% } %}

Best regards,
Jan Hermann

1 votesVote for this answer Mark as a Correct answer

David te Kloese answered on November 16, 2015 10:40

Hi,

if you use Jan's solution don't forget in Kentico 7 PortalContext was in an other namespace > CMS.CMSHelper.CMSContext.ViewMode

http://devnet.kentico.com/documentation/api-changes/kentico-8/3599

Greets,

David

2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.