Jawad Khan

Jawad's Lodge - The willingness to torture yourself before others is what makes a developer truly a unique breed.
posts - 45, comments - 149, trackbacks - 155

My Links

News

Archives

Post Categories

Image Galleries

MCMS 101 - Getting Content out of Placeholder ....

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.

Print | posted on Sunday, May 15, 2005 5:04 PM | Filed Under [ Microsoft Content Management Server ]

Feedback

Gravatar

# re: MCMS 101 - Getting Content out of Placeholder ....

Anyone wanting the VB version of this:

Imports Microsoft.ContentManagement.Publishing
Dim objPosting As Posting
lblCMSGUID = dgItem.FindControl("lblCMSGUID")
objPosting = CmsHttpContext.Searches.GetByGuid(lblCMSGUID.Text)
lblPostingName.Text = lblPostingName.Text + " - " + objPosting.CustomProperties.Item("meta_o_Date").Value
lblPostingName.Text = lblPostingName.Text + " - " + objPosting.Placeholders.Item(0).Datasource.RawContent.ToString
7/13/2005 9:47 AM | John Bellew
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: