Copied to clipboard

Flag this post as spam?

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


  • Mov3nforward 117 posts 319 karma points
    Mar 26, 2019 @ 18:08
    Mov3nforward
    0

    Multi URL Picker item Id

    I used to used the RJP.MultiUrlPicker for creating my navigations. Now that there is a default MultiURLPicker in Umbraco all of my code from previous projects does not work. (Thanks Umbraco update :).

    I used to iterate through the RJP.MultiUrlPicker items and could determine if an item was a parent item via the item.Id. The item.Id does not seem to be an option. What other options are available for the new MultiURLPicker that I could use to identify the document type for one of the items?

    var eNUsMainNavigation = navigation.GetPropertyValue<MultiUrls>("eNUsMainNavigation");
    
    <ul class="nav navbar-nav">
                        @foreach (var item in eNUsMainNavigation)
                        {
                            int childNodeCnt = 0;
                            int parentNodeId = 0;
                            string itemUrl = "";
    
                            if(item.Id != null)
                            {
                                parentNodeId = Int32.Parse(item.Id.ToString());
                                childNodeCnt = Umbraco.Content(item.Id).Children().Where("Visible").Where("hideFromMenu == false").Count();
                            }
    
                            itemUrl = childNodeCnt > 0 ? "javascript:void(0)" : item.Url.ToString();
    
                            var addClass = "";
    
                            if(childNodeCnt > 0 && !Umbraco.Content(item.Id).IsDocumentType("eNUSHomePage"))
                                { 
                                    addClass = "class=dropdown";
                                }
                                <li @addClass> 
                                @if(Umbraco.Content(item.Id).IsDocumentType("eNUSHomePage"))
                                {
                                    @*home page *@
    
                                        <a href="@item.Url.ToString()">
                                            @Html.Raw(item.Name)
                                        </a>
                                }else{
    
                                        <a href="@itemUrl">
                                            @Html.Raw(item.Name)
                                        </a>
    
                                }
    
                                @if(childNodeCnt > 0 && !Umbraco.Content(item.Id).IsDocumentType("eNUSHomePage"))
                                {
                                    <ul class="dropdown-menu">
                                        @GetDropDown(parentNodeId)
                                    </ul>            
                                }
                                </li>
                        }   
    
  • Mov3nforward 117 posts 319 karma points
    Mar 26, 2019 @ 23:42
    Mov3nforward
    0

    Anyone???

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 26, 2019 @ 23:55
    Alex Skrypnyk
    0

    Hi

    MultiUrls is deprecated.

    Instead cast the value IEnumerable or Link if you have set maximum = 1 in the property editor config. Change your code to:

    var eNUsMainNavigation = navigation.GetPropertyValue<IEnumerable<Link>>("eNUsMainNavigation");
    

    Thanks,

    Alex

  • Mov3nforward 117 posts 319 karma points
    Mar 27, 2019 @ 01:51
    Mov3nforward
    0

    I have done this, but there is not an attribute for item.id. I need to determine the document type of the item like I did before.

     @if(Umbraco.Content(item.Id).IsDocumentType("eNUSHomePage"))
                            {
                                @*home page *@
    
                                    <a href="@item.Url.ToString()">
                                        @Html.Raw(item.Name)
                                    </a>
                            }else{
    
                                    <a href="@itemUrl">
                                        @Html.Raw(item.Name)
                                    </a>
    
                            }
    
  • Chris Evans 137 posts 353 karma points c-trib
    Mar 27, 2019 @ 03:05
    Chris Evans
    101

    The new Link class for the core Multi URL Picker has a Udi property for each link.

    You can use this to query for the content node, e.g.

    var nodeOfLink = Umbraco.TypedContent(item.Udi);
    

    You may want to be careful though as links can also be external and not based on a content node, so this code would throw an exception in that case as the Udi would be null / empty, e.g.

    System.InvalidOperationException: UDIs for content items must be Umbraco.Core.GuidUdi
    

    As such you could test the Type property of the link is "Content" to make sure it's a content node first. You could also verify the value of the Udi is a valid GuidUdi object and not null.

    Hope this helps!

    Chris

  • Mov3nforward 117 posts 319 karma points
    Mar 27, 2019 @ 15:10
    Mov3nforward
    0

    Thanks Chris, that worked!

Please Sign in or register to post replies

Write your reply to:

Draft