Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Keir 3 posts 73 karma points
    Feb 02, 2016 @ 11:47
    Keir
    0

    Get avatar of publisher

    Hi there, I'm in the process of creating a bespoke blog for our site, I want to call the avatar image of the user who posted the blog article.

    I can call the publishing date and the user like this:

    Published at @CurrentPage.UpdateDate.ToString("dd/MM/yyyy") by @CurrentPage.writerName
    

    Is there a way to call the avatar of the user in a similar fashion?

    Thanks.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 02, 2016 @ 12:42
    Dan Diplo
    0

    I don't believe the avatar is exposed as a property of a published page. The best you can get from this is the ID of the person who created (or edited) the page. But from the ID you can then get a reference to the User. Something like:

    var user = UmbracoContext.Current.Application.Services.UserService.GetUserById(Model.Content.CreatorId);
    string email = user.Email;
    

    I believe Umbraco just uses Gravatar for images, so all you need is to create a hash of the email address and call their simple API. There's an example of how to do this below:

    http://stackoverflow.com/questions/3561477/asp-net-mvc-helper-for-accessing-gravatar-images

  • Keir 3 posts 73 karma points
    Feb 02, 2016 @ 14:06
    Keir
    0

    Ah that's unfortunate, thanks for your prompt response!

    • k
Please Sign in or register to post replies

Write your reply to:

Draft