Kentico CMS 7.0 Developer's Guide

Displaying avatars in transformations

Displaying avatars in transformations

Previous topic Next topic Mail us feedback on this topic!  

Displaying avatars in transformations

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

User avatars

 

User avatars can be displayed in transformations by using the <%# GetUserAvatarImage( ... ) %> method. It can be called with four different sets of parameters as described below (including examples):

 

GetUserAvatarImage(int maxSideSize, string alt)

 

<%# GetUserAvatarImage(50, HTMLEncode(GetNotEmpty("UserNickname;UserName"))) %>

 

This returns an image tag displaying the avatar contained in the AvatarGuid field of the currently transformed user, with a maximum sidesize of 50 px. and Alt tag equal to the user's Nickname or Username. The AvatarGuid field must be accessible for this method to work.

 

 

InfoBox_Exclamation

 

This overload does not support Gravatars!

 

The GetUserAvatarImage method cannot display Gravatars when called with only these two parameters. Please use one of the overloads that includes the userID parameter for this purpose.

 

GetUserAvatarImage(object userID, int maxSideSize, int width, int height, object alt)

 

<%# GetUserAvatarImage(Eval("UserID"), 200, 0, 0, Eval("UserName")) %>

 

This returns an image tag displaying the current avatar of the user with ID UserID, with a maximum sidesize of 200 px. and an Alt tag equal to the user's Username.

 

GetUserAvatarImage(object avatarID, object userID, int maxSideSize, object alt)

 

<%# GetUserAvatarImage(Eval("UserAvatarID"), Eval("UserID"), 50, Eval("UserName")) %>

 

This returns an image tag displaying the avatar with ID UserAvatarID, of user with ID UserID, with a maximum sidesize of 50 px. and Alt tag equal to the user's Username.

 

GetUserAvatarImage(object avatarID, object userID, int maxSideSize, int width, int height, object alt)

 

<%# GetUserAvatarImage(Eval("UserAvatarID"), Eval("UserID"), 0, 40, 45, Eval("UserName")) %>

 

This returns an image tag displaying the avatar with ID UserAvatarID, of user with ID UserID, with a maximum width of 40 px., maximum height of 45 px. and Alt tag equal to the user's Username.

 
Group avatars
 
Group avatars can by displayed using the same approach, with the difference that the <%# GetGroupAvatarImage( ... ) %> method is called instead:

 

GetGroupAvatarImage(int maxSideSize, object alt)

 

<%# GetGroupAvatarImage(50, Eval("GroupDisplayName", true)) %>

 

This returns an image tag displaying the group avatar specified by the AvatarGuid field of the currently transformed group, with a maximum sidesize of 50 px. and Alt tag equal to the group's Display name. The AvatarGuid field must be accessible for this method to work.

 

GetGroupAvatarImage(object avatarID, int maxSideSize, object alt)

 

<%# GetGroupAvatarImage(Eval("GroupAvatarID"), 50, Eval("GroupDisplayName", true)) %>

 

This returns an image tag displaying the group avatar with ID GroupAvatarID, with a maximum sidesize of 50 px. and Alt tag equal to the group's Display name.

 

GetGroupAvatarImage(object avatarID, int maxSideSize, int width, int height, object alt)

 

<%# GetGroupAvatarImage(Eval("GroupAvatarID"), 0, 40, 45, Eval("GroupDisplayName", true)) %>

 

This returns an image tag displaying the group avatar with ID GroupAvatarID, with a maximum width of 40 px., maximum height of 45 px. and Alt tag equal to the group's Display name.

 

Image tag

 

The following is an example of an image tag generated by the <%# GetUserAvatarImage( ... ) %> method. As you can see, the method uses the ~/CMSModules/Avatars/CMSPages/GetAvatar.aspx page to get the source image.

 

<img src="/KenticoCMS/CMSModules/Avatars/CMSPages/GetAvatar.aspx?maxsidesize=50&amp;avatarguid=42f9d97e-b0c8-43a2-8a35-62dfec5ae64a" alt="Andy" class="AvatarImage" />

 

When displaying Gravatars, the image is retrieved from the http://www.gravatar.com/ website as shown in the example below:

 

<img src="http://www.gravatar.com/avatar/9b20d3ee7a6ba98550babc044da91bfb?s=80&amp;r=g&amp;d=wavatar" alt="User avatar" class="AvatarImage" />