I wanted to quickly touch on one question that landed on our radars recently, both to discuss the solution but also highlight a couple of controls that you may not be very familiar with.
The question deals with the markup that our field controls emitted. Someone wanted to place a set of image field controls on the page, and position them right next to each other, with no space in between. On a page layout, you would typically do this using a set of image field controls, each bound to a separate image field:
<PublishingWebControls:RichImageField id="ImageField" FieldName="PublishingPageImage" runat="server"/> <PublishingWebControls:RichImageField id="ImageField2" FieldName="PageImage2" runat="server"/>
Now, if you create a page using this layout, edit the page, populate the image field controls with images, and check in the page, you'll get something that looks like this:
Why the space in between the two images? That's because the image field control emits a non-breaking space after the image. So, how do you render the images without the non-breaking space? While one could write a custom field control to take the selected image and render it out in whatever way he or she wanted, in this case custom coding is probably overkill. Instead, you can solve this using two out of box components, the edit mode panel and the field view control.
Now, an image field control stores its content as an <img> element along with any attributes you've specified for the image (alt text, sizing, border, and so on). Given this, we can do a little on-the-fly switcheroo on the page layout:
The way we do this is by putting two edit mode panels on the page layout, one configured to render in edit mode, and another configured to render in view mode:
<PublishingWebControls:EditModePanel runat=server id="EditModePanelA" PageDisplayMode="Display"> </PublishingWebControls:EditModePanel> <PublishingWebControls:EditModePanel runat=server id="EditModePanelB"> </PublishingWebControls:EditModePanel>
The first one will render its contents when people are viewing the page, while the second one will render when people are editing the page. Therefore, we will put two field controls in the second one, and then add two value controls in the first one.
<PublishingWebControls:EditModePanel runat=server id="EditModePanelA" PageDisplayMode="Display"> <SharePointWebControls:FieldValue runat="server" id="ImageFieldValue" FieldName="PublishingPageImage"/> <SharePointWebControls:FieldValue runat="server" id="ImageFieldValue2" FieldName="PageImage2"/> </PublishingWebControls:EditModePanel> <PublishingWebControls:EditModePanel runat=server id="EditModePanelB"> <PublishingWebControls:RichImageField id="ImageField" FieldName="PublishingPageImage" runat="server" /> <PublishingWebControls:RichImageField id="ImageField2" FieldName="PageImage2" runat="server"/> </PublishingWebControls:EditModePanel>
Now, if we put the page in edit mode, we get:
And in view mode, we get:
And, we're done: no more space!
This is just one example of using the edit mode panel along with the field value control. They're both valuable controls in helping you orchestrate exactly how the authoring and the viewing experience should be for a given page layout. If you have questions on how to put these controls to use, just post a comment.
--George Perantatos, ECM Program Manager