Here is my code, please can someone shed some light on getting to the crop for me please.
foreach (var post in Model.Posts) {
@if (post.HasValue("postMediaImage")) {
dynamic mediaItem = post.GetProperty("postMediaImage").Value() as Umbraco.Core.Models.PublishedContent.IPublishedContent;
var t = mediaItem.LocalCrops;
<div class="postthumb" style="background: url(@t)"></div>
}
}
The above gets my image displayed, but no crop version.
The images use new media Picker 3, and have a crop blogPost. So I am iterating down a list of entries, trying to display a thumbnail of the image for the main post.
the examples in the documentation do not seem to work:
@{
foreach (var entry in Model.Medias)
{
}
}
I cannot seem to replace the Model.Media bit with my post to get to the image and be able to use the GetLocalCropUrl helper.
To translate it into your models, the code could look like:
@foreach (var post in Model.Posts)
{
if (post.HasValue("postMediaImage"))
{
var mediaItem = post.Value<IEnumerable<MediaWithCrops>>("postMediaImage").FirstOrDefault();
var crops = mediaItem.LocalCrops;
<div class="postthumb" style="background: url(@Url.GetCropUrl(crops, "cropAlias"))"></div>
}
}
Getting crops from New Media Picker 3
HI, I am upgrading to Umbraco 8.15 and trying to use the new Media Oicker 3 with crops, like a crop with an alias of blogPost.
I can select the image and I cannot get it to display the specific crop.
I have even been through the documentation page here: https://our.umbraco.com/Documentation/Fundamentals/Backoffice/property-editors/built-in-property-editors/Media-Picker-3/
Here is my code, please can someone shed some light on getting to the crop for me please.
The above gets my image displayed, but no crop version.
The images use new media Picker 3, and have a crop blogPost. So I am iterating down a list of entries, trying to display a thumbnail of the image for the main post.
the examples in the documentation do not seem to work:
@{ foreach (var entry in Model.Medias) { } }
I cannot seem to replace the Model.Media bit with my post to get to the image and be able to use the GetLocalCropUrl helper.
Thank you in advance for your help.
Kind regards,
Pete
Hi,
It seems you are reading the image as a
IPublishedContent
, when you should be reading it as aMediaWithCrops
. This is what is documented here https://our.umbraco.com/Documentation/Fundamentals/Backoffice/property-editors/built-in-property-editors/Media-Picker-3/#multiple-enabled-without-modelsbuilderTo translate it into your models, the code could look like:
HTH :)
Hi Søren, Excellent, thank you for the feedback. done the trick. Kind regards,
Pete
is working on a reply...