Copied to clipboard

Flag this post as spam?

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


  • Dan 12 posts 91 karma points
    Oct 21, 2014 @ 12:53
    Dan
    0

    Show Image From ID

    Hi!

    I'm hoping this isn't too silly a question - but I have a media upload field, and I'm not sure how to show the image within my cshtml macro script... I can return an id, but not the image. Hoping someone can take a look at my snippet below and point me in the right direction. I'm using Umbraco 7. Thanks!!

    @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)){
    <div class="news-listing">
        <div class="row">          
                <div class="col-md-3">
                    <!-- IMAGE (@item.icImage) SHOULD SHOW IF mediaType is news -->
                    Image
                </div>           
            <div class="col-md-9">
            <h2><a href="@item.Url">@item.icTitle</a></h2>
            <span class="news-date">Posted In: @item.mediaType</span>
            @item.icIntro
            <p><a href="@item.Url">Read more</a></p>
            </div>
            </div>
        </div>
    }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 21, 2014 @ 13:10
    Dennis Aaen
    0

    Hi Dan,

    What if you do something like this will you get the image then.

    @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)){
    <div class="news-listing">
        <div class="row">         
                <div class="col-md-3">
                    @{
                        var dynamicMediaItem = Umbraco.Media(item.icImage);
                    }
                     <img src="@dynamicMediaItem.Url" alt="@dynamicMediaItem.Name"/>
                </div>          
            <div class="col-md-9">
            <h2><a href="@item.Url">@item.icTitle</a></h2>
            <span class="news-date">Posted In: @item.mediaType</span>
            @item.icIntro
            <p><a href="@item.Url">Read more</a></p>
            </div>
            </div>
        </div>
    }

    In my example I assume that you are using the Built-in media picker property editor: http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors/Media-Picker

    Hope this helps,

    /Dennis

  • Dan 12 posts 91 karma points
    Oct 21, 2014 @ 14:03
    Dan
    0

    Hi Dennis,

    Thanks for the response! I'm using the Media Picker - however when I tried to use the snippet you suggested, I get an 'Error loading MacroEngine script'. Any ideas?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 21, 2014 @ 14:25
    Dennis Aaen
    100

    Hi Dan,

    I think I know why you are getting the error, the snippet is for MVC and you are using the old DynamicNode Razor try this instead.

    @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)){
        <div class="news-listing">
            <div class="row">         
                    <div class="col-md-3">
                        @{
                            var dynamicMediaItem = Library.MediaById(item.icImage);
                           
                        }
                         <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
                    </div>          
                <div class="col-md-9">
                <h2><a href="@item.Url">@item.icTitle</a></h2>
                <span class="news-date">Posted In: @item.mediaType</span>
                @item.icIntro
                <p><a href="@item.Url">Read more</a></p>
                </div>
                </div>
        </div>
    }

    Hope this helps,

    /Dennis

  • Dan 12 posts 91 karma points
    Oct 21, 2014 @ 15:03
    Dan
    0

    Aha - this works perfectly! Thanks so much!!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 21, 2014 @ 15:33
    Dennis Aaen
    0

    Hi Dan,

    You are welcome, could you please mark the question as solve, as you can see you have a green tick on each post, and to mark the question as solve you need to click on green tick for the post that solve your issue.

    It´s a good thing to do, so other people that come across this post can see what works for you.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft