Copied to clipboard

Flag this post as spam?

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


  • Sam 63 posts 126 karma points
    Apr 18, 2015 @ 14:12
    Sam
    0

    Convert an old razor code to new umbraco 7 partial view

    Hi all - 

    I have an old razor code that i have written :

    @{

    var mediaFolder = Library.MediaById(1058);

           if(mediaFolder.Children.Count()>0)

    {

    foreach(var photo in mediaFolder.Children)

    {

    if(photo.IsLast())

    {

    @:{image : '@photo.uploadSlider', info: "@photo.addTextForTheImage"}

    }

    else

    {

    @:{image : '@photo.uploadSlider', info: "@photo.addTextForTheImage"},

    }

    }

    }

     

    }

     

     

    I really need some help to convert that to new syntax for Umbraco 7 (  Library.MediaById to Umbraco.Media etc..)

    Please help me on this - so that on future code I get somethng to referenced on.

     

    Thank You

    Sam//

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 18, 2015 @ 14:22
    Dennis Aaen
    0

    Hi Sam,

    I think that you should be good with this code.

    @{
        var mediaFolder = Umbraco.Media(1058);

           if(mediaFolder.Children.Any()){
                foreach(var photo in mediaFolder.Children{
                    if(photo.IsLast()){
                        @:{image : '@photo.uploadSlider', info: "@photo.addTextForTheImage"}
                    }else{
                        @:{image : '@photo.uploadSlider', info: "@photo.addTextForTheImage"},
                    }
    }

        }
    }

    You can find some documentation here: https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/#Media%28%29

    Hope it works for you.

    /Dennis

  • Sam 63 posts 126 karma points
    Apr 18, 2015 @ 15:06
    Sam
    0

    Thanks Dennis but still not working ; (

    I have added an image cropper and written this :

    @{

        var mediaFolder = Umbraco.Media(1058);

     

           if(mediaFolder.Children.Any()){

                foreach(var photo in mediaFolder.Children{

    if(photo.IsLast()){

                        @:{image : '@Umbraco.Media(@photo.id).GetCropUrl("uploadHomeSlide", "slideCrop")', info: "@photo.addTextForTheImage"}

                    }

    else{

                        @:{image : '@Umbraco.Media(@photo.id).GetCropUrl("uploadHomeSlide", "slideCrop")', info: "@photo.addTextForTheImage"},

                    }

             }

        }

    }

    I get this error : Error loading Partial View script

    Any other clue?

    Thks again

     

     

    /Sam

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 18, 2015 @ 15:20
    Dennis Aaen
    0

    Hi Sam,

    Okay so you are working with the image cropper. You can find the documentation about the image cropper here: https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Image-Cropper

    Another good resource to learn how the image cropper is working is by seen this episode from uHangout.https://www.youtube.com/watch?v=bQsvGmnYaUU

    @{
        var mediaFolder = Umbraco.Media(1058);

           if(mediaFolder.Children.Any()){
                foreach(var photo in mediaFolder.Children{
                    if(photo.IsLast()){
                        <img src='@photo.GetCropUrl("uploadSlider", "banner")' alt="@photo.addTextForTheImage" />
                    }else{
                        <img src='@photo.GetCropUrl("uploadSlider", "banner")' alt="@photo.addTextForTheImage" />
                    }

                }
        }
    }

    Where the banner is the name of the crop.

    Hope this can help you furhter, how to use the image cropper.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft