Transformation:<%@ Register TagPrefix="cms" TagName="Media" Src="~/CMSInlineControls/MediaControl.ascx" %>
showing the media image tag here:
<%# MyFunctions.GetMediaImgTagOnly(Eval<string>("Photo"), "about-peopleImage") %>
Functions:private static readonly string MySiteCodeName = "/MyCmsSite";
/// <see cref="http://devnet.kentico.com/Forums/f45/t16108/Media-Selection-Url-Issue.aspx"/>
public static string GetMediaUrl(object txtValue)
{
string aliasRemovedUrl = String.Empty;
if (!(txtValue == null | txtValue == DBNull.Value))
{
aliasRemovedUrl = txtValue.ToString().Replace(MySiteCodeName, "~");
}
return aliasRemovedUrl;
}
/// <see cref="http://devnet.kentico.com/Forums/f45/t16228/conditional-statement-in-transformation.aspx"/>
public static string GetMediaImgTagOnly(object txtImage, object cssClass)
{
string mediaImgTag = String.Empty;
if (!(txtImage == null | txtImage == DBNull.Value | String.IsNullOrEmpty(txtImage.ToString())))
{
//work with the image
mediaImgTag = "<cms:Media id=\"mediaImageID\" runat=\"server\"";
if (!(cssClass == null | cssClass == DBNull.Value | String.IsNullOrEmpty(cssClass.ToString())))
{
mediaImgTag += " class=\"" + cssClass + "\"";
}
mediaImgTag += " Url=\"" + GetMediaUrl(txtImage) + "\" />";
}
return mediaImgTag;
}