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:
- Extended Attachment Placeholder for MCMS 2002
- QuickTime Placeholder Control MCMS2002
- PDF Placeholder Control
- Shockwave Flash Placeholder Control
- Windows Media Player Placeholder Control
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”>
<PARAM NAME=movie VALUE=”<%# Container.AttachmentUrl %>“>
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#000000>
<EMBED src=”<%# Container.AttachmentUrl %>”
As you can see this is not very complicated. The PresentationTemplateContainer of the SingleAttachmentPlaceholderControl exposes the following properties:
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: