SharePoint CEWP – source includes dynamic content
Many people have used the the Content Editor WebPart to provide an easy way to inject some JavaScript into a web page to do things like hide the left navigation or show snowflakes.
In SharePoint 2010 the good old Content Editor WebPart is still around and even has some nice new features like format as XHTML, however I discovered one feature that I suspect is more of a bug – or perhaps an undocumented feature
Scenario
You have used the content editor web part to put some placeholders on the page, a couple of DIV tags and the like. You have another web part (it could be the same one) that does some funky Client API calls to get some information to render in those place holders < all looking good for a simple no code solution so far.
Now you decide that you want to copy you handy work to another site, this is just a quick ‘Information Worker’ hack so no need for any Visual Studio or WSPs here.
Edit the page and select the content editor web part, the one that has has some content dynamically added. Click on the HTML > Edit HTML Source option and da-dah the dynamic content is included in the source.
Upshot
This could be a great thing if you wanted to get at all of the code, but I suspect this is not what you expected. The problem is that if you now make a minor change – say you wanted to add something and click save, you will hard code whatever values had been added.
I would prefer the Content Editor Web Part source Editor to ONLY show me what I has actually added to it in the web part properties. I suspect the reason for the bug is likely someone trying to reduce the calls to the server.
Serious Problem
The problem is actually quite serious as you only need to visit the page, click Edit Page and then Stop Editing for it to update the content. This really does mean that you will have to stop using the CEWP in this way at least for the Beta.
