Copied to clipboard

Flag this post as spam?

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


  • Elad Lachmi 112 posts 144 karma points
    Apr 20, 2012 @ 10:51
    Elad Lachmi
    0

    Check if Multi-URL picker has items

    Hi,

    I am trying to create an unordered list, which will not show if the content editor has not added an items to the list.

    I have the following code:

    <umbraco:Macro Language="cshtml" runat="server">
                          @if (@Model.HasProperty("upperListLinks") && @Model.GetProperty("upperListLinks").Value != String.Empty)
                          {
                            <ul class="green_squers">
                            @foreach (var link in Model.upperListLinks.urlpicker) {
                                <li><href="@link.url" @Html.Raw(link.newwindow ="True" "target=\"_blank\"" "")>@link.linktitle</a></li>
                            }
                          </ul>
                          }
                      </umbraco:Macro>

    Any ideas on how I can get this to work?

    Thank you!

  • Douglas Ludlow 210 posts 366 karma points
    Apr 20, 2012 @ 19:02
    Douglas Ludlow
    2

    If the Multi Url Picker's alias is upperListLinks, then the following should work:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @if (Model.upperListLinks.GetType() == typeof(DynamicXml) && Model.upperListLinks.Count() > 0)
    {
    <ul class="green_squers">
    @foreach (var link in Model.upperListLinks) {
    <li><a href="@link.url" @Html.Raw(link.newwindow == "True" ? "target=\"_blank\"" : "")>@link.linktitle</a></li>
    }
    </ul>
    }

    If the current Model does not have a Multi Url Picker with the alias of upperListLinks, then Model.upperListLinks.GetType() will return a DynamicNull object and the condition will be false.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies