Copied to clipboard

Flag this post as spam?

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


  • Chad 25 posts 196 karma points
    Aug 12, 2015 @ 21:14
    Chad
    0

    Multi URL Picker global navigation in Umbraco 7

    I can't be the only one who needs to create a fixed global navigation menu at the top of the page that contains links to existing pages in the site that are included in the primary navigation tree, as well as specified external links - right?

    This probably won't make sense but I have spent 3 solid days trying to get the Multi-URL Picker (RJP) to work. I have my primary navigation all working correctly based on how the pages are arranged in the content window, but I basically need another menu at the top of the page where the user can specify the links to go in there - not dependent on the structure in the content window.

    The Multi-URL works if I have a new Document Type and I put in some urls, then browse to "/top-nav-links", but if I try to include this like a partial I get a runtime error, if I try to copy out the code that is working for it to display the links on a new page I get a runtime error, and if I go custom and try to go down the new root node and find this field I get runtime errors.

    This is the current structure:

    Section I
    --Secondary I
    ----Tertiary I
    --Secondary II
    ----Tertiary II
    Section II
    --Secondary
    ----Tertiary
    Top Nav Links
    

    Any ideas on how I can have a root node document that contains the "linkPicker" in it (Top Nav Links), then get the url for each of the links to display globally across each section, secondary, and tertiary page?

    Thanks!

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 13, 2015 @ 07:49
    Dave Woestenborghs
    0

    Hi Chad,

    We build this kind of functionality a lot in our sites.

    What we mostly do is add a MultiUrlPicker property to the homepage or settings node where the editor can pick the items for the fixed menu.

    Then in our views we look up the homepage/settings node and render the picked links from the property

    Dave

  • Chad 25 posts 196 karma points
    Aug 13, 2015 @ 14:07
    Chad
    0

    Hi Dave,

    It sounds like that's the same way I'm trying to do it. I am able to search through the root nodes and get the one that has the MultiUrlPicker in it (both by Id or but checking of the property is there), but then I'm stuck trying to get the values from the picker. Lots of yellow error screens as I try to work though it! How are you getting back the links and page name from the picker?

    This is my first time working with Umbraco so I'm learning on the fly. I have a not-as-elegant solution in place now where the user can select a checkbox on any page to add it to the global mac and then put in a number to have the links sorted that way. It would be much easier to use the picker though!

    Would you be able to share how you're getting the values back from the picker?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 13, 2015 @ 14:09
    Dave Woestenborghs
    0

    Hi Chad,

    On the github page of the package are some code examples. Both using strongly typed IPublishedContent or a dynamic variant

    https://github.com/rasmusjp/umbraco-multi-url-picker/

    Dave

  • Chad 25 posts 196 karma points
    Aug 13, 2015 @ 15:13
    Chad
    0

    Unfortunately neither of those examples have worked with rendering the list in a different node which is leaving me scratching my head. The dynamic example doesn't work at all, even when viewing the actual page where the picker is added.

    If I add the Multi Url Picker type to a document type, let's say "Top Nav Links" per the structure above, and use the example with var multiUrlPicker = Model.Content.GetPropertyValue<MultiUrls>("topBarLinks"); I get the list output at domain.local/top-nav-links no problem. If I use the dynamic example, nothing renders at all.

    So using the Typed way, if I then try to use that code within a partial after getting the node that contains the picker, I always get an error of:

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    This highlights the line if (multiUrlPicker.Any()) as the problem. If I remove the if statement, I'll still get the same exception error but this time referencing the @foreach (var item in multiUrlPicker) line.

    Am I way off base on this?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 13, 2015 @ 15:22
    Dave Woestenborghs
    0

    Can you post your entire code of the partial ? This will help in finding the problem

    Dave

  • Chad 25 posts 196 karma points
    Aug 13, 2015 @ 16:16
    Chad
    0

    Hey Dave,

    I've already removed all of the code in order to implement my other solution (and to keep it from erroring) so I could move on and revisit this after.

    I believe I was using uQuery to get the node that has the picker in it (var topLinkMenu = uQuery.GetNodesByName("Top Navigation Links");) but trying to do it that way again now I can't use .GetProperty/.HasProperty/.GetPropertyValue, etc. to find the picker.

    This is the view that does work, per the example, rendering the links at domain.local/top-navigation-links:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using RJP.MultiUrlPicker.Models
    @{
      Layout = null;
    }
    
    @{
      var multiUrlPicker = Model.Content.GetPropertyValue<MultiUrls>("topBarLinks");
      if (multiUrlPicker.Any())
      {
        <ul>
        @foreach (var item in multiUrlPicker)
        {
          <li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
        }
        </ul>
        }
      }
    

    This is the partial where I need to get the menu to render (my current alternate way of listing items is commented out):

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using RJP.MultiUrlPicker.Models
    @{ 
      var siteRoot = Umbraco.TypedContentAtRoot();
      var topLinkMenu = uQuery.GetNodesByName("Top Navigation Links");
    }
    <nav id="topNav" role="navigation">
      <div class="content-wrapper">
        <ul>
          <li><a href="tel:1-800-123-4567" data-type="tel">1-800-123-4567</a></li>
    
          //// Need to render links here, foreach item in multiUrlPicker ... ////
    
          @* TEMP SOLUTION
          @foreach (var node in siteRoot) {
            foreach (var page in node.AncestorOrSelf(1).Descendants(1).OrderBy(x => x.GetPropertyValue("topBarOrder")).ThenBy(x => x.Name)) {
              if (page.HasValue("showInTopBar")) {
                if (page.HasValue("altTopNavTitle")) {
                  <li><a href="@page.Url" title="@page.Name">@page.GetPropertyValue("altTopNavTitle")</a></li>
                } else {               
                  <li><a href="@page.Url" title="@page.Name">@page.Name</a></li>
                }
              }
            }
          }
          *@
    
          <li><i class="fa-search"></i>
        </ul>
      </div>
    </nav>
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 14, 2015 @ 06:57
    Dave Woestenborghs
    0

    Probably you can do something like this.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using RJP.MultiUrlPicker.Models
    @{ 
      var siteRoot = Umbraco.TypedContentAtRoot();
    
      // get the page with the navigation set
      var topBarItemsNode = siteRoot.Childern<YourTopNavilinksDoctype>().FirstOrDefault();
    }
    @if(topBarItemsNode != null)
    {
    <nav id="topNav" role="navigation">
      <div class="content-wrapper">
        <ul>
          <li><a href="tel:1-800-123-4567" data-type="tel">1-800-123-4567</a></li>
    
          var multiUrlPicker = topBarItemsNode.GetPropertyValue<MultiUrls>("topBarLinks");
      if (multiUrlPicker.Any())
      {
        <ul>
        @foreach (var item in multiUrlPicker)
        {
          <li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
        }
        </ul>
        }
    
          <li><i class="fa-search"></i>
        </ul>
      </div>
    </nav>
    }
    

    Mind this code is written in this blog post and not test so it can contain errors.

    Dave

  • Chad 25 posts 196 karma points
    Aug 17, 2015 @ 18:20
    Chad
    100

    Dave,

    I was able to dig deeper based on your last reply and finally have it working! I had to set the topBarItemsNode to siteRoot.Where("DocumentTypeAlias == \"TopNavigationLinks\"").FirstOrDefault();

    In the end, this is what ended up working based on your input:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using RJP.MultiUrlPicker.Models
    @{ 
      var siteRoot = Umbraco.TypedContentAtRoot();
      var topBarItemsNode = siteRoot.Where("DocumentTypeAlias == \"TopNavigationLinks\"").FirstOrDefault();
    }
    <nav id="topNav" role="navigation">
      <div class="content-wrapper">
        <ul>
          <li><a href="tel:800-123-4567" data-type="tel">1-800-123-4567</a>    </li>
    
          @if(topBarItemsNode != null)
          {
          var multiUrlPicker = topBarItemsNode.GetPropertyValue<MultiUrls>("topBarLinks");
            if (multiUrlPicker.Any())
            {
              foreach (var item in multiUrlPicker)
              {
                <li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
              }
            }
          }
    
          <li><i class="fa-search"></i>
        </ul>
      </div>
    </nav>
    

    Thank you for your guidance!

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 18, 2015 @ 05:50
    Dave Woestenborghs
    0

    Glad you sorted it out. Don't forget to mark this post as solved so others can find the solution as well.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft