Kyle Kingsbury A Sitecore web development blog!

Sitecore Page Mode Switcher


Every now and again I find myself looking for a way to easily switch the Sitecore PageMode for a code block for either testing what happens when in specific modes or render renderings a specific way. The easiest solution is to use SetDisplayMode on the Context Site:

While this is very clean and simple, it often leads to repetitive code blocks. I wonder why Sitecore doesn’t provide a PageModeSwitcher as part of the out of the box API just like the ContextItemSwitcher, SiteContextSwitcher, or DatabaseSwitcher (any others to be honest).

Since a switcher is not available out of the box, we can create our own using the SetDisplayMode method and implement IDisposable:

And to use, we simply do the following:

Do you have any tips and tricks that you want to share? Comment below!

Add comment

Kyle Kingsbury A Sitecore web development blog!

Recent Posts