Copied to clipboard

Flag this post as spam?

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


  • radmanmm 117 posts 108 karma points
    Jan 09, 2012 @ 22:58
    radmanmm
    0

    Why is there no simple answer to this!?! - Razor, Parameter, Media

    Hello,

    I have been looking through the all the information I can find about how to do this, it really should not take 2 hours of research to get this to work, very frustrating.

    Simple need.

    I have a macro, macro has a parameter for a mediaCurrent item.  I want to put a link to the media in my html via Razor.

    I have tried the Walkthroughs, I have tried searching the forum, I have tried searching google.  Doesn't seem it should be so hard to find answer.

    Perhaps walkthroughs should include reading media from parameter and actually getting its url, I did not see this.  And by this I mean a clear example of how to get the value out of the parameter and load the media with it, instead of several pieces of sample code not directly correlated to each other.

    Code I am trying to get to work:

    @using umbraco.MacroEngines
    @{
      var description Parameter.description;
      var marketingContentID Parameter.marketingContent;
      var thumbnailImageID Parameter.thumbnailImage;
      
      dynamic marketingContent Model.Media(marketingContentID);
      dynamic thumbnailImage Model.Media(thumbnailImageID);
    }

    <div class="box"><href="@marketingContent.umbracoFile"><img src="@thumbnailImage.umbracoFile" alt="" /></a><br />
    <h2>Description</h2>
    @description
    </div>


  • Funka! 398 posts 661 karma points
    Jan 10, 2012 @ 01:45
    Funka!
    1

    Hi radmanmm,

    Maybe try this?

    @{
      ...
      var marketingContent = Library.MediaById(marketingContentID);
      var thumbnailImage = Library.MediaById(thumbnailImageID);
    }

    Hopefully this helps.  The "Library" is an intrinsic helper that I have been using in my own hacked-together solutions.  Best of luck!

  • Funka! 398 posts 661 karma points
    Jan 10, 2012 @ 01:50
    Funka!
    1

    P.S., there is a lovely cheat-sheet (just found it on my desk to reference here for you) which is where I first learnt of this, that you can get at http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet ...

    Again, best of luck!

  • Tom Madden 253 posts 455 karma points MVP 4x c-trib
    Jan 10, 2012 @ 08:32
    Tom Madden
    0

    Hi radmanmm,

    Sorry I can't give a full answer right now, but it you convert your thumbnailImage value to an int, you can use library.GetMedia, with an additional boolean parameter 'deep'.

    Thsi will give you an XPathNodeIterator object, if you select the first tem and then the Value property, you will have the path to the image. I'll post an example code t lunchtime today.

    HTH

    Tom

  • radmanmm 117 posts 108 karma points
    Jan 10, 2012 @ 16:26
    radmanmm
    0

    Funka! - YOU ROCK!!! thank you so much, this was killing me!

  • Gareth Evans 142 posts 334 karma points c-trib
    Jan 12, 2012 @ 23:00
    Gareth Evans
    0

    n.b. you use Model.Media("propertyName") when you have a property on your current model containing an ID which should be loaded as a media item.
    So let's say you have catImage on your document type, you'd want to go Model.Media("catImage").Url to get the URL for the cat.

    You use Library.MediaById (which is also aliased as Model.MediaById but that's deprecated now) when you have an ID number (or that ID comes from querystring) and you want to get the media item.

    In short, Funka! is right but I thought I'd supply a bit more detail on why.

Please Sign in or register to post replies

Write your reply to:

Draft