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.
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.
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.
Although it works, does anyone know if there is another way to retrieve the culture for GetCropUrl
Thanks George
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
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
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 :
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
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
is working on a reply...