Copied to clipboard

Flag this post as spam?

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


  • Garry Bain 149 posts 124 karma points
    Jun 12, 2017 @ 13:36
    Garry Bain
    0

    Archetype and media picker (going insane)

    Hello,

    I am using Archetype (quite successfully so far) but I am unable to get the path of my single media picker image I have chosen! All I can return the is "Value" of the image and I have googled extensively and cannot find a solution to this, my code is below:

      @foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("myArch")) {
      var imageUSP = @Umbraco.TypedContent(fieldset.GetValue("uspImage"));
      @imageUSP 
     }
    

    The "@imageUSP" returns the Value of 1077 - in this example. I've tried appending .Url and .ImageUrl and I cannot for the life of me figure out how to get the path from here!

    Any help would be wonderful

    Thanks, Garry.

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Jun 12, 2017 @ 13:50
  • Alex Brown 129 posts 620 karma points
    Jun 12, 2017 @ 15:35
    Alex Brown
    0

    What version of Umbraco are you using? If it's 7.6 then follow Paul's guide on his site.

    Otherwise Umbraco.Media().Url should work, as that number you're seeing is the content id.

    Edit: also you shouldn't need the extra "@"'s when declaring inside the foreach when at the top of the function. (I know I put it in my example by accident)

  • Garry Bain 149 posts 124 karma points
    Jun 12, 2017 @ 15:37
    Garry Bain
    0

    Using Umbraco version 7.5.12 - I'll give it another crack with fresh eyes in the morning as it's driving me mental!

    Cheers

  • Alex Brown 129 posts 620 karma points
    Jun 12, 2017 @ 15:48
    Alex Brown
    100

    Apologies, my first comment was utterly wrong (going to delete it).

    What you want to do is:

    var imageUsp = Umbraco.Media(fieldset.GetValue("uspImage")).Url

    You can then pop that variable into an image source like so

    "< img src="@imageUsp"/>"

  • Garry Bain 149 posts 124 karma points
    Jun 12, 2017 @ 15:55
    Garry Bain
    0

    Thank you Alex you're a star!

Please Sign in or register to post replies

Write your reply to:

Draft