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:
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:
v. useful - is this is the docs <anywhere /> !? - all I could find was the property definition
if it would be there I would have known it earlier.
I had a talk with the Developer who implemented this. But this feature came in very late and missed the deadline for being documented.
It was intended to relief the fact that only 3 out of the box placeholder controls are shipped with the product.
Stefan, this is a really great little gem that you found. This can save a lot of time.
Great info! Although I couldn't get it right...
If I create a new posting with my template, is it supposed to have the attachment (the flash file) pre-selected? Because mine still says "no attachment set", which makes it just a normal single attachment placeholder... Where am I going wrong?
In authoring mode it is a normal Attachment Placeholder control. You need to select the flash file and save the page.
Then - in presentation mode - the flash will be displayed and run rather than shown as attachment.
Just one more thing...
How can I make the web form the size of the flash placeholder only? i.e. - not maximized like it is, but only as big as the flash movie itself? Thanks for your help, much appreciated.
The size needs to be given at the object tag and embedd tag as shown above.
How to do this for PDF,Word,PPT's etc
For PDF: check out the PDF placeholder control. For Word and PPT you might want to render an IFRAME with a SRC pointing to the document URL.
Is there any way to avoid the <span>..</span> tags that are inserted around the PresentationTemplate?
not easy. You could write a HttpModule which removes them. Or a render method in the template.
Yes - but then I might as well write my own custom placeholder control :-/
I have never understood why Microsoft puts <span>-tags around everything.