Copied to clipboard

Flag this post as spam?

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


  • Levente Kosa 129 posts 345 karma points
    May 29, 2015 @ 09:09
    Levente Kosa
    0

    GetCropUrl problem within nested foreach

    I have some problem with crop function. I'm using a nested Multiple Node Tree Picker, but the GetCropUrl doesn't work. The crop function is ok, I've already used it.

     

        @{
        if (CurrentPage.HasValue("artists"))
        {
        var artistList = CurrentPage.artists.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var artistCollection = Umbraco.Content(artistList);
        foreach (var artist in artistCollection)
        {
        if (artist.HasValue("coverImages"))
        {
        var coverImagesList = artist.coverImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var coverImagesCollection = Umbraco.Media(coverImagesList);
        foreach (var coverImage in coverImagesCollection.RandomOrder().Take(1).Where("Visible"))
        {
          <img src="@coverImage.GetCropUrl(305, 195)"/>
        }
        }
        }
        }
        }
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    May 29, 2015 @ 10:11
    Jeavon Leopold
    0

    So if you change to:

    <img src="@coverImage.Url"/>
    

    Does it work although with the original images?

  • Levente Kosa 129 posts 345 karma points
    May 29, 2015 @ 11:19
    Levente Kosa
    0

    Yes, it works with the original images.

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    May 29, 2015 @ 13:01
    Jeavon Leopold
    0

    Ok, what HTML is rendered when you set it back to GetCropUrl?

  • Levente Kosa 129 posts 345 karma points
    May 29, 2015 @ 21:33
    Levente Kosa
    0

    Sorry, how do you mean "what HTML"?  I don't understand. 

  • Levente Kosa 129 posts 345 karma points
    May 30, 2015 @ 21:56
    Levente Kosa
    0

    I noticed something, but I don't understand. I started to use Id.
    When I use this:

    foreach (var coverImage in coverImagesCollection)
       <p>@coverImage.Id</p>
       <img src="@Umbraco.TypedMedia(1105).Url"/>
    }

    I got back the the image id from @coverImage.Id, and the image is working.

    When I use this:

    foreach (var coverImage in coverImagesCollection)
       <img src="@Umbraco.TypedMedia(coverImage.Id).Url"/>
    }

    The image is still good.

    After I'm cropping with fix id.

    foreach (var coverImage in coverImagesCollection)
       <img src="@Umbraco.TypedMedia(1105).GetCropUrl(305, 195)"/>
    }

    Working, but then:

    foreach (var coverImage in coverImagesCollection)
       <img src="@Umbraco.TypedMedia(coverImage.Id).GetCropUrl(305, 195)"/>
    }

    I got an error:

    'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetCropUrl'

    How is that possible? I'm not professional with this.

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    May 30, 2015 @ 22:46
    Jeavon Leopold
    100

    Hi Levente,

    Could you post how coverImage is defined?

    I could take a guess and say that coverImage.Id is dynamic so then try this:

       <img src="@Umbraco.TypedMedia((int)coverImage.Id).GetCropUrl(305, 195)"/>
    

    Jeavon

  • Levente Kosa 129 posts 345 karma points
    May 30, 2015 @ 23:21
    Levente Kosa
    0

    Yes, you were right! (int)coverImage.Id helped, now it's working perfectly.

    Thank you so much your help, I really appreciate it.

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    May 31, 2015 @ 00:26
    Jeavon Leopold
    0

    You're welcome!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies