Displaying Avatar of user who has created Blog post using transformation.

   —   
This article shows how to get user avatar and how to use it in transformation. This applies globally to any type of document not just Blog Post.
In general, you can create your own (custom) function (Adding custom functions to transformations) and add it into ~/App_Code/CMSModules/Blogs/BlogFunctions.cs file. Below you can find code example on how to retrieve user avatar from user who has previously created current document:

public static string GetUserAvatar(object userId)
{

int id = ValidationHelper.GetInteger(userId, 0);
UserInfo user = CMS.SiteProvider.UserInfoProvider.GetUserInfo(id);

if (user.UserAvatarID != 0)
{
AvatarInfo avinf = CMS.SiteProvider.AvatarInfoProvider.GetAvatarInfo(user.UserAvatarID);
return "<img src=" + CMS.GlobalHelper.UrlHelper.ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx") + "?avatarguid=" + avinf.AvatarGUID.ToString() + "&maxsidesize=100' alt=''/>";
}

else
{
return "";
}

}

Then you can call this method in your transformation using following code:

<%# BlogFunctions.GetUserAvatar(Eval("DocumentModifiedByUserID")) %>




See also:

Applies to: Kentico CMS 4.x
Share this article on   LinkedIn