The most common functionality required in any MCMS project is to get access to the content contained in the placeholder. MCMS has different kind of placeholder definitions like HtmlPlaceholder, ImagePlaceholder, XmlPlaceholder and AttachmentPalceholder. It is desirable to get the content according to the type of placeholder for e.g in case of ImagePlaceholder you want the URL of the Image or some other properties rather then just a blog of string or HTML. You can get that blog by pl.Datasource.RawContent for any type of placeholder.
Here is how to access the content of different types of placeholder.
First make sure to have the following using statement at the top of your utility class
using Microsoft.ContentManagement.Publishing.Extensions.Placeholders;
then
private string ProcessPlaceholderContent(Placeholder pl)
{
string content = string.Empty ;
if (pl is HtmlPlaceholder)
{
content = ((HtmlPlaceholder)pl).Html ;
}
else
{
if (pl is ImagePlaceholder)
{
content = ((ImagePlaceholder)pl).Src ;
if (content == string.Empty)
content = "~/images/Common/FFFFFF.gif";
}
else
{
if (pl is AttachmentPlaceholder)
{
content = ((AttachmentPlaceholder)pl).Url ;
}
else
{
if (pl is XmlPlaceholder)
{
content = ((XmlPlaceholder)pl).XmlAsString ;
}
else
{
content = pl.Datasource.RawContent ;
}
}
}
}
return content;
}
Also Note that in case of empty placeholder I don't want to display broken image so I am replaying with a FFFFFF.gif that is 1 pixel transparent image.
Placeholder pl here is the name of the placeholder as defined in MCMS Template Explorer and not the id of the Placeholder Control that is dragged in to HTML view but the name used in BindToPlaceholder of that Control.