I've been looking at SharePoint 2007 from a Web Content Management perspective, and the first thing I want to know is how do I customise the HTML output. When displayed to the end user, rendering is validating XHTML should not be made complicated.
Customising the layouts doesn't always mean the default output is invalid, just that's not not what you want. Best example is a heading TextField - you want to surround it in
, but ONLY if it has content - empty tags not only look messy, they cause rendering issues.
And I did, but unfortunately no single fix covers everything. One of the most important things I have discovered is that the major field controls, like RichLinkField and RichImageField, do NOT store structured data; it's just HTML. This means that you can't have access to the URL portion of the field.
Below are the common field controls and a sample of modified output:
Note the use of the EditModePanel to stop the inner FieldValue control from causing an exception when going into edit mode.
I currently have not figured out a way to template the output of the RichHtmlField. Should anyone else attempt this, I'll cover what I've tried/learned so far:
- RichHtmlField ignores the DisplayTemplate (and Template) property.
- The CustomTemplate property is ignored by most, if not all, field controls.
- Internally, RichHtmlField overrides the RenderFieldForDisplay method and renders the HTML out directly, which explains why it ignores the template properties.
- TextField throws an exception if assigned the FieldName of the RichHtmlField (even if the RichHtmlField is removed from the page).
- RichLinkField renders nothing - most likely because the regular expressions it uses to parse the HTML internally aren't matching anything. This also applies to RichImageField as it is a subclass of RichLinkField.
- FieldValue, like RichHtmlField, overrides the default rendering process itself - meaning that templates do not work with it.