Copied to clipboard

Flag this post as spam?

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


  • Bent Holz 100 posts 273 karma points
    Jul 27, 2017 @ 12:43
    Bent Holz
    0

    Image Cropper - going from 6.2.6 to 7.6.4

    Had to recreate this thread...

    Just started out with 7.x and Razor and am trying to figure out the logic... sigh! I'm trying to set up a simpel image slider using image cropper/media picker. Using Partial Views and Query builder for the first time, this is what i got:

    @{
        var selection = Umbraco.TypedContent(1146).Children("slidebillede").Where(x => x.IsVisible()).OrderBy("CreateDate desc");
    }
    
        <ul>
        @foreach(var item in selection){
        <li>
                @{
                    if (item.HasValue("picFrontslide")){
    
                        var nodeId = item.Id;
                        var mediaItem = item.GetPropertyValue("picFrontslide");
    
                        if (mediaItem != null)
                        {
                            <img src="@nodeId" />
                            <img src="@mediaItem" />
                            <img src="@Umbraco.Content(nodeId).GetCropUrl("picFrontslide", "frontslide")" />
                        }
                    }
                }
        </li>
        }
    </ul>
    

    This renders out

    <ul>
        <li>
           <img src="1154" />
           <img src="1152" />
           <img src="1152?mode=pad&amp;rnd=131456337220000000" />
    
        </li>
        <li>
          <img src="1153" />
          <img src="1151" />
          <img src="1151?mode=pad&amp;rnd=131456337240000000" />
        </li>
    </ul>
    

    So... I get the page id, the id of the selected media (value of "picFrontslide") and the selected media including what I assume is crop data?!... Since this is not a solution I looked at what Leopold wrote in a former post regarding the image has to be parsed from the media archive before adding crop.

    var mediaGet = Umbraco.TypedMedia(Model.Content.GetPropertyValue<int>("picFrontslide"));
    if (mediaGet != null)
     {
      <img src="@Url.GetCropUrl(mediaGet, "frontslide")" />                    
     }
    

    This results in nothing...

    Been searching through the forum and now I'm just more confused. Can anyone help me out here and maybe explain how this works now?

    Cheers

  • Bent Holz 100 posts 273 karma points
    Jul 27, 2017 @ 12:45
    Bent Holz
    0

    I have not installed Umbraco Core Property Value Converters...

    Is this necessary?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2017 @ 12:51
    Alex Skrypnyk
    0

    Bent, it's part of the core, please check - umbracoSetting.config setting: in section settings/content, setting EnablePropertyValueConverters.

  • Bent Holz 100 posts 273 karma points
    Jul 27, 2017 @ 12:55
    Bent Holz
    0

    It is set to "true" :)

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2017 @ 12:56
    Alex Skrypnyk
    0

    so you can get image like:

    var mediaGet = Model.Content.GetPropertyValue<IPublishedContent>("picFrontslide");
    
  • Bent Holz 100 posts 273 karma points
    Jul 27, 2017 @ 12:58
    Bent Holz
    0

    I get nothing here...

    @{
        var selection = Umbraco.TypedContent(1146).Children("slidebillede").Where(x => x.IsVisible()).OrderBy("CreateDate desc");
    }
    
    
    <ul>
        @foreach(var item in selection){
        <li>
                @{
                    if (item.HasValue("picFrontslide")){
    
                        var mediaGet = Model.Content.GetPropertyValue<IPublishedContent>("picFrontslide");
                        if (mediaGet != null)
                        {
                            <img src="@mediaGet.GetCropUrl("frontslide")" />                    
                        }
                     }
                }
        </li>
        }
    </ul>
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2017 @ 13:04
    Alex Skrypnyk
    100

    Bent

    Model.Content - is current page

    no sense to use it in the loop

    each time this code:

    var mediaGet = Model.Content.GetPropertyValue<IPublishedContent>("picFrontslide");
    

    Does the same, get "picFrontslide" from the current page.

    Maybe it should be like this:

    var mediaGet = item.GetPropertyValue<IPublishedContent>("picFrontslide");
    

    Thanks,

    Alex

  • Bent Holz 100 posts 273 karma points
    Jul 27, 2017 @ 13:10
    Bent Holz
    0

    Bingo!...

    You wouldn't happen to have a link to some documentation, so I might get to understand what is going on here?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2017 @ 13:16
    Alex Skrypnyk
    1

    "Umbraco Core Property Value Converters" package is part of the core now, you can find more info about this here - https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/

Please Sign in or register to post replies

Write your reply to:

Draft