Copied to clipboard

Flag this post as spam?

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


  • Greg McMullen 49 posts 195 karma points
    Feb 06, 2013 @ 16:57
    Greg McMullen
    0

    Using DynamicMedia for Image Picker

    I am currently trying to build a Macro for displaying of items with an Image, Links and Text. I have all items working aside from if the pageThumbnail is empty. The entire macro breaks at this point.

    If I remove the dynamic media and the image (and surronding if) the Macro works. How can I target the media call to see if it's blank, so it doesn't crash the macro? Everything I've tried has only caused render failures or errors stating "variable media not defined."

    The code in question is below:

    @foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize))
    {
        dynamic media = new DynamicMedia(@item.pageThumbnail);
        <div class="news-list" style="margin-bottom:10px; clear:both;">
            <h2><a href="@item.Url">@item.Name</a></h2>  
        @if ( media.UmbracoFile != "" ) {
            <img class="float-lmr" src="/imagegen.ashx?width=100&[email protected]" title="@item.Name" alt="@item.Name" />  
        }
        <p>@item.pageSummary</p>
        <p><a href="@item.Url" title="Read more about @item.Name">Read more about @item.Name</a></p>
    </div>
    }
  • Mike Chambers 635 posts 1252 karma points c-trib
    Feb 06, 2013 @ 23:50
    Mike Chambers
    0

    think you can use

    if (media.UmbracoFile != typeof(DynamicNull))

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 07, 2013 @ 13:15
    Jeroen Breuer
    0

    Don't know if you're using DAMP for the Image Picker, but you could try the DAMP Razor Model. It has a Count and Any property to see if there are media items.

    Jeroen

  • Greg McMullen 49 posts 195 karma points
    Feb 07, 2013 @ 14:19
    Greg McMullen
    100

    Okay, for the moment I have it working. I completely scrapped the idea of the "dynamicMedia" property.

    @Mike - I couldn't get your option to work and @Jeroen we aren't using DAMP to my knowledge.

    @foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize))
        {
    var image = "";
    <div class="news-list" style="margin-bottom:10px; clear:both;">
    <h2><a href="@item.Url">@item.Name</a></h2>
    @if ( item.Media("pageThumbnail") != null ) {
    image = item.Media("pageThumbnail").umbracoFile;
    <img class="float-lmr" src="/imagegen.ashx?width=100&image=@image" title="@item.Name" alt="@item.Name" />
    }
    <p>@item.pageSummary</p>
    <p><a href="@item.Url" title="Read more about @item.Name">Read more about @item.Name</a></p>
    </div>
    }
Please Sign in or register to post replies

Write your reply to:

Draft