Everyday is a good day to learn something new about MCMS 2002.
Today I learned that lots of custom placeholder controls I and others have written are not really necessary! The same functionality can be achieved with the standard Placeholder controls and and a badly documented feature: PresentationTemplates
A PresentationTemplate allows to modify the default behaviour of SingleAttachmentPlaceholderControls and SingleImagePlaceholderControls without actually modifying the PlaceholderControl itself and without the need to create a custom placeholder control. This means that all Placeholder Controls which only modify the presentation mode behaviour of an existing placeholder control can be replaced with this out-of-the box method.
Here is a list of placeholder controls which can replace easily with this method:
How to implement this method? Very easy! The following code changes an SingleAttachmentPlaceholderControl into a FlashPlaceholderControl:
This is how an SingleAttachmentPlaceholderControl is usually embedded in a template file:
<cms:SingleAttachmentPlaceholderControl id="AttPhCtrl1" runat="server" PlaceholderToBind="AttPh" CssClass="ph"></cms:SingleAttachmentPlaceholderControl>
Most of you will have seen this before. Here is now the changed code to convert this into an FlashPlaceholderControl:
<cms:SingleAttachmentPlaceholderControl id="AttPhCtrl1" runat="server" PlaceholderToBind="AttPh" CssClass="ph">
<PresentationTemplate>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
WIDTH=640 HEIGHT=480>
<PARAM NAME=movie VALUE="<%# Container.AttachmentUrl %>">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#000000>
<EMBED src="<%# Container.AttachmentUrl %>"
quality=high bgcolor=#000000
WIDTH="640" HEIGHT="480"
TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</EMBED>
</OBJECT>
</PresentationTemplate>
</cms:SingleAttachmentPlaceholderControl>
As you can see this is not very complicated. The PresentationTemplateContainer of the SingleAttachmentPlaceholderControl exposes the following properties:
- AttachmentText
- AttachmentUrl
- PlaceholderControl
Using the PlaceholderControl object it is easy to access all other relevant objects, may it be the AttachmentPlaceholder object itself or may it be the Page object of the current page.
There are benefits and drawbacks in using this method:
Benefit: Customization and updates of the code is very easy and does not require a recompile of a custom placeholder control. It does not even require a recompile of the template project as only the ASPX page and not the code behind file needs to be changed!
Drawback: if you have to include this configured placeholder control on multiple templates then I would still use a custom placeholder control to the effort to add this code multiple times.
So for rapid prototyping this is definitly an alternative to get to a quick solution!
A similar PresentationTemplate is also available for the SingleImagePlaceholderControl. Here it exposes the following properties:
- AlternateText
- DisplayHeight
- DisplayWidth
- ImageUrl
- NavigateUrl
- PlaceholderControl