Need to know if an EPiServer CMS page is being rendered in edit mode or not? Then the PageEditing class is your friend.
After trying a number of ways to determine if a page or block is rendered within EPiServer CMS’ edit mode or not I stumbled upon a nice little helper class in the EPiServer API named PageEditing. Using this we can easily check if the current request is for a content object in edit mode in templates and preview pages:
//using EPiServer.Editor; bool inEditMode = PageEditing.PageIsInEditMode;
I tried this for both pages and block in Web Forms as well as with MVC and it seems to work everywhere.
The PageEditing class also has a couple of other nice members, such as the method GetEditUrl for retrieving the URL for editing a content object and GetChannel which returns the current channel, if any.
PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.
My book
Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!
Comments
comments powered by Disqus