Sitefinity CMS has a built-in WYSIWYG page editor. WYSIWYG is an acronym for What You See Is What You Get. This term is used to describe a system in which content displayed during editing looks similar (if not identical) to the final output
The alternative to WYSIWYG page editing is a sandboxed composition mode where content looks nothing like the final results. In this environment, editors must constantly toggle into a preview mode to see the results of content changes. Sitefinity deliberately choose a WYSIWYG editing experience to minimize the steps (and pain) needed to edit, preview & publish content changes.
However, to create an accurate representation of the final page Sitefinity needs to execute the controls & code used on the page. In some circumstances, this can create problems. Thankfully there is an easy solution to this problem.
Disabling WYSIWYG
A few weekends ago during the WAM2010 charity event, I used an XML Sitemap User Control created by Sitefinity Partner Roger West Creative. This control creates an XML representation of a web site’s sitemap that can be easily consumed by search engines.
To do this, the control needs to override Sitefinity’s default page rendering and instead create an XML document. This functionality would wreak havoc in Sitefinity’s page editor. In fact, once the control is dropped onto the page it would be impossible to Edit or Remove.
To avoid these problems the control needs disabled when in edit mode. Sitefinity adds a querystring parameter (cmspagemode) to the URL each time a page is being edited (or previewed):
- cmspagemode=edit – Sitefinity is in page edit mode.
- cmspagemode=preview – Sitefinity is in page preview mode.
To prevent Sitefinity from executing the XML Sitemap Control Roger West added a small bit of code to disable the control’s functionality when it is running in preview or edit mode.
protected void Page_Load(object sender, EventArgs e){ // Create output only if page is not in cms edit/preview mode if (Page.Request["cmspagemode"] == null) { // This code will not be executed when Sitefinity is in edit/preview mode }}That’s it. Any code wrapped inside will not be executed when Sitefinity is in edit or preview mode. If necessary, WYSIWYG editing can now be disabled.