There’s a post title that just reaches out and grabs you, right? Heh. OK, experienced SharePoint users know that it is not possible to version the content in a content editor web part. Possibly, you discovered this in the worse possible way like I did.
Our corporate SharePoint intranet uses the publishing features and version control to version the pages we build. And what many of us foolishly assumed was that the versioning was, you know, all the stuff on the page. The web parts, their placement, the stuff inside them. Nope. Versioning preserves the metadata about the publishing page. Not the goodies inside the web parts. I learned this pretty quickly when someone deleted the content from a CEWP on a page. No problem, thought I, I just went to the version history and loaded a version of the page from before the change occurred. How sad for me. Same page loaded, with the same content. As in: my missing CEWP content was still missing. For all time. Time to get cracking with a recode of that missing stuff.
Later, a method for versioning the content came to me and I tried it out and lo, it worked. I thought that surely I had just overlooked this method in someone else’s blog posts or tips-n-tricks, but I never saw it anywhere else, so I’ll blog it here. I’m not saying I’m the inventor here–I could not be because it is just too simple a method.
OK, so what is the content editor web part, really? It’s a container for a snippet of html and not much more than that. It’s a simple way to tuck a script or a style sheet or just some formatted verbiage on the page. All other options on the web part are strictly stock–chrome, audience targeting, etc. The combination of these things can actually make for a pretty useful tool, but it has some flaws. One is that the content itself is not preserved from damage (as noted above) by any versioning. The second is that the rich text editor is known to jack with your markup and it won’t ask you first. There’s not a setting for “trust me and don’t touch my markup.” We had a problem like this happen just the other day: someone edited an existing web part that had been created using the source editor (where script editing is somewhat safer) but they edited it with the rich text editor and suddenly a script was missing. Too bad it was the crucial SUBMIT function that made this little form snippet actually work.
So, there’s the Rich Text Edtor which is not good and the source editor and then there’s an option to tell the CEWP to go get the contents of a URL. This last option is the obvious (to me) way to get versioning and CEWP to work together. Here’s how it works.
First, create a library. Create it at the highest level you can–site collection root would be the best choice. If not, at least put it at the highest level site you can. Set up the versioning settings to enable your content to be versioned to whatever level you desire.
Next: open the text editor of your choice to edit the markup for your web part source. I prefer to save the result with the extension .html even if it is not a complete and well-formed html file. In fact, it should not be: it should be a snippet.
Save the resulting file in your library.
Place your content editor web part. In the source URL setting, choose the URL to your uploaded content.
As I said, apologies to anyone else who’s already figured this out or blogged it. I was not able to find your stuff despite searching for it.
Note this method has additional benefits of providing you a single location to edit content that appears on multiple pages in your sites. I have a snippet that renders a button that users click to start a new Lombardi BPM process and I need to put it on several sites. I have found it safer to manage that little snippet in a text file that I can version and then reference it from many pages with separate CEWPs using the source URL.
It may help that I worked for years supporting a Plumtree portal and using Plumtree Publisher. That is basically how the Plumtree Publisher system works: edit the cotent in one place and then put it on any page you need by placing the portlet.