Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Feb 03, 2015 @ 14:16
    Bjarne Fyrstenborg
    0

    Display Custom Label when no item is selected

    I have a XML Dropdown Picker, where the editor can pick a region.

    When a item is picked I can display a Custom Label, e.g. the node id + node name and make it as a link to the picked node.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        IPublishedContent content = Umbraco.TypedContent(Model.MacroParameters["key"]);
        if (content != null)
        {   string link = "/umbraco/#/content/content/edit/" + content.Id;
            <a href="@link">@content.Id: @content.Name</a>
        }
        else
        {
            @Html.Raw("<span>No region selected.</span>")
        }   
    }

     

    But for "Region 2" (which is not picked) it doesn't seem to render the macro or reach the else block.

    Furthermore if I change the dropdown back to the initial value (blank value) it still display the relation on "Region 1" even the relation shouldn't be active anymore and the macro cache is disabled.

    /Bjarne

  • Damian Green 452 posts 1433 karma points
    Feb 03, 2015 @ 15:09
    Damian Green
    0

    Hi Bjarne

    What if you check the Model.MacroParameters["key"] for an empty or null value instead of calling the TypedContent helper?

    Maybe the helper is returning something which makes the if always true? I cant remember the default behaviour without looking it up.

    Damian

  • Damian Green 452 posts 1433 karma points
    Feb 03, 2015 @ 15:16
    Damian Green
    0

    Just tested and typedcontent does seem to return null when it cant find a node... What value is in Model.MacroParameters["key"] when it is empty ?

    Are you getting an error and nothing displayed because the error is caught further up the stack?

    Just throwing a few ideas around for you.

    Damian

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Feb 03, 2015 @ 15:22
    Bjarne Fyrstenborg
    0

    Hi Damian

    I tried also to check if the macroparameter has a value... problem is that the macro only seems to render, when there is a relation.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        @Html.Raw("<span>No region selected.</span>")
    }

    This is only printed when the node is selected, otherwise it doesn't seem to render the macro.

    /Bjarne

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Feb 03, 2015 @ 15:26
    Bjarne Fyrstenborg
    0

    nuPickers.RelationLabels only render the script Custom Label through the macro, when there is a relation to the selected node. So at the moment in the current version it doesn't seem to be possible to render a "empty/blank/fallback" label.

Please Sign in or register to post replies

Write your reply to:

Draft