Copied to clipboard

Flag this post as spam?

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


  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Jul 24, 2014 @ 19:58
    Janae Cram
    0

    Using the Articulate Image Cropper for Authors

    I see that you're using the image cropper for an Author Image, but if I add a crop to it, I don't see a way in the strongy typed model to then pull the crop of the image rather than just the default image itself. How do I go about doing that?

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jul 24, 2014 @ 23:53
    Shannon Deminick
    0

    The PostModel and all other articulate models implement IPublishedContent, so you have direct access to all the normal ways of working with Umbraco data as well. So you can still do @Model.Content.GetPropertyValue ....

    I can add a nicer way of doing it to the strongly typed model though if you want to create an issue for it?

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Jul 25, 2014 @ 00:04
    Janae Cram
    0

    Well, in an ideal world full of unicorns and rainbows, I would want something like this: https://github.com/rustyswayne/Buzz.Hybrid/blob/master/src/Buzz.Hybrid/ImageExtensions.cs

     

    In the meantime, I'll submit an issue for it and just use IPublishedContent ;) Thanks for clarifying!

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jul 25, 2014 @ 00:07
    Shannon Deminick
    0

    Pretty sure your world of unicorns and rainbows already exists, no?

    https://github.com/umbraco/Umbraco-CMS/blob/7.1.5/src/Umbraco.Web/ImageCropperTemplateExtensions.cs

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Jul 25, 2014 @ 00:11
    Janae Cram
    0

    Right, but that's off IPublisheContent and not a strongly typed image, isn't it?

     

    (You'll have to forgive me, I'm jumping into this with a learning curb as we just started doing a Hybrid Framework for everything here)

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jul 25, 2014 @ 00:21
    Shannon Deminick
    1

    Yup, so the underlying call to populate Articulate's AuthorModel is:

        public AuthorModel Author
        {
            get
            {
                if (_author != null)
                {
                    return _author;
                }
    
                _author = new AuthorModel
                {
                    Name = Content.GetPropertyValue<string>("author", true)
                };
    
                //look up assocated author node if we can
                if (RootBlogNode != null)
                {
                    var authors = RootBlogNode.Children(content => content.DocumentTypeAlias.InvariantEquals("ArticulateAuthors")).FirstOrDefault();
                    if (authors != null)
                    {
                        var authorNode = authors.Children(content => content.Name.InvariantEquals(_author.Name)).FirstOrDefault();
                        if (authorNode != null)
                        {
                            _author.Bio = authorNode.GetPropertyValue<string>("authorBio");
                            _author.Url = authorNode.GetPropertyValue<string>("authorUrl");
    
                            _author.Image = authorNode.GetCropUrl(propertyAlias: "authorImage", imageCropMode: ImageCropMode.Max);
                        }
                    }
                }
    
                return _author;
            }
        }
    

    So until I add something nicer, you can create your own extension method on PostModel like :

    public static class PostModelExtensions
    {
        public static string GetAuthorCropUrl(this PostModel postModel)
        {
            if (postModel.RootBlogNode == null) return string.Empty;
            var authors = postModel.RootBlogNode.Children(content => content.DocumentTypeAlias.InvariantEquals("ArticulateAuthors")).FirstOrDefault();
            if (authors == null) return string.Empty;
            var authorNode = authors.Children(content => content.Name.InvariantEquals(postModel.Author.Name)).FirstOrDefault();
            return authorNode != null 
    
                //TODO: Adjust the overloaded parameters to suit your needs here:
                ? authorNode.GetCropUrl(propertyAlias: "authorImage", imageCropMode: ImageCropMode.Max) 
    
                : string.Empty;
        }
    }
    
  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Jul 25, 2014 @ 00:22
    Janae Cram
    1

    Genius! Thank you so much for the help :)

Please Sign in or register to post replies

Write your reply to:

Draft