Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Testing umbraco v8 i would like to show an image on my multilingual website.
I have danish and english language.
It should be possible to have different images on each language, but if no image is set on danish, it should fallback to the english image. In this case it is a image cropper data type, but could be a image picker as well.
It works fine if i do this:
@Model.Value("introImage", fallback: Fallback.ToLanguage)
But what if I want to have the cropped image?
<img src="@Url.GetCropUrl(Model, propertyAlias: "introImage", height: 550, width: 550)" class="banner-image img-responsive" )" />
How can i implement fallback here? Is it possible?
@Model.Value<IPublishedContent>("introImage", fallback: Fallback.ToLanguage)?.GetCropUrl("cropAlias")
The GetCropUrl() is an extensionmethod on IPublishedContent, so you first can get the fallback IPublishedContent and then use the GetCropUrl() on that IPublishedContent
Thanks, but that does not seem to work.
I get the following: CS1503: Argument 1: cannot convert from 'method group' to 'HelperResult' :(
I'm not on my PC, but try removing the ) at the end of my code example. I think that throws the exception
I did see the little typo, and had removed that. But no luck. Still the same error. There must be a way :(
I couldn't get this working either - have created a PR to add some overloads to the GetCropUrl method that should allow using language and fallbacks. Not sure if a better way already exists, but will perhaps see when the PR is reviewed.
Interesting, I have no errors and it works as expected.
I'm trying to understand the error you're getting. Can it be you must surround your code with ( and ), like this:
<img src="@(Model.Value<IPublishedContent>("image", fallback: Fallback.ToLanguage)?.GetCropUrl("card"))" />
I think this issue is that the field is of type "Image Cropper" (rather than "Media Picker") - and hence you don't get an IPublishedContent back?
I think you're right, but I don't get any errors when I change my property from Media picker type to Image Cropper type.
When using Image Cropper directly on content type there is indeed a issue with getting the fallback value, so good job @Andy you made a PR for this.
(Temporary?) solution maybe for @Hundebol is moving to Media picker instead of the Image Cropper directly. That is how my example was configured.
Hi Andy and Corné,
Thanks the effort. Really appreciated. This was driving me nuts, so glad to see that there actually seems to be an issue.
I will let this thread be unsolved until we know further about Andy's PR :)
Thanks for the help so far you guys :)
I worked around this by checking the model value first to see if it was null and rendering a constant if it was:
Layout = "Master.cshtml";
var searchResultImage = Model.SearchResultImage;
@if (searchResultImage != null)
<img src="@Url.GetCropUrl(Model, "searchResultImage", "Search Result")" />
<img src="@Constants.DefaultValues.DefaultSearchResultImage" />
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted