Copied to clipboard

Flag this post as spam?

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


  • ckincincy 4 posts 44 karma points
    Nov 29, 2021 @ 17:21
    ckincincy
    0

    Get URL for MediaPicker content on custom data type

    Have a data type defined with many values, one being a media picker.

    This gets the data:

    @{
        Layout = "master.cshtml";
        var players = Umbraco.Content(Guid.Parse("<uniqueid>"))
        .ChildrenOfType("player")
        .Where(x => x.IsVisible());
    
    }
    

    This mostly works:

        @foreach(var player in players)
                        {
                            <div class="col-md-4 py-1">
    <a title="#@player.Value("primetimeJerseyNumber") - @player.Value("playerName") - @player.Value("playerHighSchool")" href="@player.Url()"><img src="@Umbraco.Media(player.Value("playerProfileImage"))" class="rounded-lg" /></a></div>
                        }
    

    What is not working is figuring out how to get the profile image.

    Have tried many variations:

    @Umbraco.Media(player.Value("playerProfileImage"))
    @Umbraco.Media(player.Value("playerProfileImage")).Url
    @Umbraco.Media(player.Value("playerProfileImage")).Url()
    @player.Value("playerProfileImage").Url()
    @player.Value("playerProfileImage").Url
    

    And others, what am I missing here?

  • ckincincy 4 posts 44 karma points
    Nov 30, 2021 @ 02:42
    ckincincy
    0

    Fought with this for most of a day, can't find the magic sauce. Help is appreciated.

  • ckincincy 4 posts 44 karma points
    Nov 30, 2021 @ 04:14
    ckincincy
    100

    I have it working, why did I need to make the call into two lines?

                @foreach(var player in players)
                {
                            var imageUrl = player.Value<MediaWithCrops>("playerProfileImage").Url();
                    <div class="col-md-4 py-1"><a title="#@player.Value("primetimeJerseyNumber") - @player.Value("playerName") - @player.Value("playerHighSchool")" href="@player.Url()"><img src="@imageUrl" class="rounded-lg" /></a></div>
                }
    

    Works, if I do this... it does not:

    @foreach(var player in players)
                    {
                        <div class="col-md-4 py-1"><a title="#@player.Value("primetimeJerseyNumber") - @player.Value("playerName") - @player.Value("playerHighSchool")" href="@player.Url()"><img src="@player.Value<MediaWithCrops>("playerProfileImage").Url()" class="rounded-lg" /></a></div>
                    }
    
  • Frank Laumann 39 posts 303 karma points
    Nov 30, 2021 @ 06:48
    Frank Laumann
    0

    Hi Ckincincy

    It might be bc of the qoutes (").

    It might work to do

    <img src="@(player.Value<MediaWithCrops>("playerProfileImage").Url())" class="rounded-lg" />
    

    Best regards Frank

Please Sign in or register to post replies

Write your reply to:

Draft