Copied to clipboard

Flag this post as spam?

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


  • Matt Taylor 859 posts 2052 karma points
    Mar 27, 2013 @ 15:42
    Matt Taylor
    0

    How to detect if no items have been picked?

    I have this problem for a long time now but I really need to address it.

    I've configured a DAMP datatype to allow for the picking of zero or more items.
    I've got some Razor script that wants to display just the first item which is great if one has been picked but it errors if one has not.

    No matter what checks I try to put in place I cannot get to check for no items without error.

    The basic script:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines;

    @{
        // Get the first image in the collection.
        var image = Model.image[0].Image;
        var url = image.umbracoFile;   
       
        <img src="@url" alt="@image.description" />   
    }

    Can someone help me fix this?

    Regards,

    Matt

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 27, 2013 @ 15:45
    Jeroen Breuer
    100

    If you try the DAMP Razor Model (use the old Razor version for this code) it has an .Any property which is false if no items are selected.

    Jeroen

  • Matt Taylor 859 posts 2052 karma points
    Mar 27, 2013 @ 15:53
    Matt Taylor
    0

    Thanks Jeroen,

    I'm using Umbraco v6, should I not be using the 2nd version, DAMP Property Editor Value Converter?

    Regards,

    Matt

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 27, 2013 @ 15:58
    Jeroen Breuer
    0

    It's a long story, but there are 2 versions of Razor in Umbraco. You can see it by the inherit code in your Razor file:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage = new MVC Razor

    @inherits umbraco.MacroEngines.DynamicNodeContext = old Macro Razor

    For both I wrote a converter. More info:

    https://groups.google.com/d/msg/umbraco-dev/WC_7OTF_lO0/31b_k4vsJ90J

    http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker/digibiz-advanced-media-picker/38888-Nothing-Seems-to-Work#comment141954

    Jeroen

  • Matt Taylor 859 posts 2052 karma points
    Mar 27, 2013 @ 16:01
    Matt Taylor
    0

    Ah OK, yes I'm not using the MVC rendering engine. I understand.

    Thanks,

    Matt

  • Matt Taylor 859 posts 2052 karma points
    Mar 27, 2013 @ 16:25
    Matt Taylor
    0

    Works nicely, thanks.

Please Sign in or register to post replies

Write your reply to:

Draft