Copied to clipboard

Flag this post as spam?

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


  • George Phillipson 108 posts 287 karma points
    May 13, 2021 @ 21:48
    George Phillipson
    0

    GetCropUrl Culture

    Hi All

    As GetCropUrl does not allow retrieving the culture on a multi-lingual website I have had to use the following in my EventHandler class.

    string imgXxlEn     = image.MediaUrl(culture: "en-GB", propertyAlias: "cmsGlobalSettingsDocTypeFullWidthImage").GetCropUrl(cropAlias: "XXL", width: 2100, imageCropMode: ImageCropMode.Stretch, quality: 80);
    

    Although it works, does anyone know if there is another way to retrieve the culture for GetCropUrl

    Thanks George

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 14, 2021 @ 06:58
    Dave Woestenborghs
    0

    Hi George,

    Media items stored in the library are culture invariant, so you can't get them for a specifice culture.

    But maybe you have a media picker on culture variant content ?

    Dave

  • George Phillipson 108 posts 287 karma points
    May 14, 2021 @ 07:02
    George Phillipson
    0

    Hi Dave I have it working, just wanted to know if there is another way. Always good to know more than 1 way to do something :) Regards George

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 14, 2021 @ 07:10
    Dave Woestenborghs
    0

    Hi George,

    Normally you don't need to care about cultures when getting content. That is only needed when you want to get content from another specific language.

    So I would do this :

    var mediaUrl = string.Empty;
    var mediaItem = Model.Value<IPublishedContent>("cmsGlobalSettingsDocTypeFullWidthImage");
    
    //// get it with fallback to another language
    //var mediaItem = Model.Value<IPublishedContent>("cmsGlobalSettingsDocTypeFullWidthImage", fallback: Fallback.ToLanguage);
    
    if (mediaItem != null)
    {
        mediaUrl = mediaItem.GetCropUrl(cropAlias: "XXL", width: 2100, imageCropMode: ImageCropMode.Stretch, quality: 80);
    }
    

    Here I just get the media item for the current language. The commented out line get's it with a fallback to another language (can be configured in language set utp).

    Then if a media item exisits I get the crop url from that.

    Dave

  • George Phillipson 108 posts 287 karma points
    May 14, 2021 @ 11:17
    George Phillipson
    0

    Hi Dave

    I should have been more specific, it is a multi-lingual website (2 languages) and the code is in a class so I don't have access to the model as I'm capturing the save event on the doctype.

    As I mentioned, it works as is, I was just wondering if there was another way.

    Regards

    George

Please Sign in or register to post replies

Write your reply to:

Draft