Here’s just a quick little piece of Dynamic Content I threw together yesterday together with a partner. It’s for when you want editors to be able to insert flash elements directly in XHTML fields. A bit like inserting images – except that instead of an <img> tag we now want <object> and <embed> tags.
The code for this is fairly straightforward :
namespace EPiServer.Research.DynamicContent{public class FlashDC : IDynamicContent
{ protected PropertyDocumentUrl flash; protected PropertyNumber width; protected PropertyNumber height; /// <summary> /// Setup properties /// </summary> public FlashDC() { flash = new PropertyDocumentUrl(); flash.Name = "Flash file "; width = new PropertyNumber(300); width.Name = "Width"; height = new PropertyNumber(300); height.Name = "Height";}
#region IDynamicContent Members /// <summary> /// We'll use the render method instead /// </summary> /// <param name="hostPage"></param> /// <returns></returns> public System.Web.UI.Control GetControl(PageBase hostPage) {throw new NotImplementedException();
}
public EPiServer.Core.PropertyDataCollection Properties { get { PropertyDataCollection pdc = new PropertyDataCollection();pdc.Add(flash);
pdc.Add(width);
pdc.Add(height);
return pdc;}
}
public string Render(PageBase hostPage)
{return string.Format("<object width=\"{1}\" height=\"{2}\"><param name=\"movie\" value=\"{0}\"><embed src=\"{0}\" width=\"{1}\" height=\"{2}\"></embed></object>", flash.ToString(), width.ToString(), height.ToString());
}
public bool RendersWithControl
{ get { return false; }}
public string State
{get
{return flash.ToString() + "|" + width.ToString() + "|" + height.ToString();
}
set
{string[] parts = value.Split('|');
if (parts.Length == 3) {flash.ParseToSelf(parts[0]);
width.ParseToSelf(parts[1]);
height.ParseToSelf(parts[2]);
}
}
}
#endregion}
}
And it’s registrered in web.config like this:
<add description="Displays a flash element" name="FlashPlugin" type="EPiServer.Research.DynamicContent.FlashDC, FlashDC"/>
