Copied to clipboard

Flag this post as spam?

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


  • Mark Watson 118 posts 384 karma points
    Dec 16, 2019 @ 01:47
    Mark Watson
    0

    dynamic menu with anchor links

    We have been stuck on this for a while and what ever we try does not seem to work and apparently this is not an Umbraco v8 bug. Although Umbraco will not tell us how to do this?? We are new to umbraco and working in Umbraco cloud v8.

    We are trying to add anchor links to a dynamic menu. Our client creates the anchor link with the anchor link tool.

    We thentry and add the link to the dynamic menu.

    enter image description here

    This should give us the path /services#communication, but we get the following services/communication and therefore does not work.

    enter image description here

    Our dynamic menu code is below

    @helper RenderPageLink(IPublishedContent item)
    {
        bool isActive = Model.Id == item.Id;
    
    
        if (!item.Value<bool>("disableDropdown") && item.Children != null && item.Children.Where(x => x.IsVisible()).Any())
        {
            IEnumerable<IPublishedContent> childItems = item.Children.Where(x => x.IsVisible());
            bool textOnly = item.Value<bool>("textOnlyInNavigation");
    
            <li class="dropdown">
                <a class="dropdown-toggle @(textOnly ? "textonly" : null) @(isActive ? "active" : null)" data-toggle="dropdown"  href="@item.Url">@item.Name <span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                    @RenderChildren(childItems)
                </ul>
            </li>
        }
        else
        {
            <li role="presentation" class="@(isActive ? "active" : null)">
                <a href="@item.Url">@item.Name</a>
    
    
            </li>
        }
    }
    

    Can someone point us in the right direction. This should be simple to achieve so we are missing something obvious.

  • Graham Davis 110 posts 376 karma points
    Dec 17, 2019 @ 04:04
    Graham Davis
    0

    Mark,

    This problem sounds familiar to me. As I recall, the problem has something to do with MVC Razor. Have you tried Encoding the URL's?

  • Mark Watson 118 posts 384 karma points
    Dec 17, 2019 @ 23:12
    Mark Watson
    0

    Thanks Graham

    We tried

        <a href="@HttpUtility.UrlPathEncode(item.Url)">@item.Name</a>
    

    and derivatives of

    <a href="@HttpUtility.UrlPathEncode("#" + item.Url)">@item.Name</a>
    

    to try and force the "#" but unfortunately no change. we still get services/communication where we need services#communication.

    We can do this manually but then our client will not be able to add anchors when they want.

    This is the only CMS we have used that seems to have an issue with this simple task.

  • Mark Watson 118 posts 384 karma points
    Dec 20, 2019 @ 03:03
    Mark Watson
    0

    Ok, I am nearly there. I have added this

     <a href="@HttpUtility.UrlPathEncode(Request.Url.AbsoluteUri + "services#" + item.Name("anchorServices"))">@item.Name </a>
    

    which works for the drop down menu, but now the top menus if they do not have a drop down have the "services#" in front of the path so they do not work.

    ie our about us link is now /services#aboutus where it should be /aboutus.

    Does any one have any ideas?

  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Dec 22, 2019 @ 08:58
    Matt Barlow | jacker.io
    0

    It's not exactly clear what you are trying to achieve. Your render page link code is in no way connected to the list of anchor links you are creating. I think you should also show us the @RenderChildren() method code. Also can you show us the example of content that has the dynamic links?

    Reading your helper method it says if not disable dropdown + has children then render dropdown html and pass the children into a RenderChildren helper method else render out node name and url

    There is no code there, that says access a property on my node that has a list of the in-page dynamic links.

    As i say, show us all of the code, tell us exactly what you are trying to achieve and give us the structure of the documents you have set up, then I am sure I can help you out.

  • Graham Davis 110 posts 376 karma points
    Dec 22, 2019 @ 14:22
    Graham Davis
    0

    What happens if you write the link using @HTML.Raw()?

    @HTML.Raw("<a href="HttpUtility.UrlPathEncode(Request.Url.AbsoluteUri + "services#" + item.Name("anchorServices"))">@item.Name </a>")
    
Please Sign in or register to post replies

Write your reply to:

Draft