Copied to clipboard

Flag this post as spam?

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


  • BEWD 90 posts 302 karma points
    Nov 04, 2016 @ 13:46
    BEWD
    0

    Hi All

    I am using the below code on a Master Page to display a set of Navigational links that are controlled from the Homepage node, This works fine on the homepage but as soon as you navigate to a sub page the links disappear.

    @{
    if (CurrentPage.HasValue("relatedLinks") && CurrentPage.relatedLinks.ToString().Length > 2)
    {
        <ul>
            @foreach (var item in CurrentPage.relatedLinks)
            {
                var linkUrl = (bool)item.isInternal ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.link;
                var linkTarget = (bool)item.newWindow ? "_blank" : null;
                <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>
            }
        </ul>
    }
    }  
    

    The code above is from https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/related-links

    How do I go about making this recursive so it can be seen on all pages? I am using Umbraco 7.5.3 and the code is in a Template not a partial view

    Thanks

    Ben

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 04, 2016 @ 19:35
    Dennis Aaen
    100

    Hi Ben,

    I have looked at your code, and what you need to do is go up to the root node and get the values from there.

    You can do it with the code below.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var rootNode = CurrentPage.Site();
        if (rootNode.HasValue("relatedLinks") && rootNode.relatedLinks.ToString().Length > 2)
        {
            <ul>
                @foreach (var item in rootNode.relatedLinks)
                {
                    var linkUrl = (bool)item.isInternal ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.link;
                    var linkTarget = (bool)item.newWindow ? "_blank" : null;
                    <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>
                }
            </ul>
        }
    }  
    

    Hope this helps,

    /Dennis

  • BEWD 90 posts 302 karma points
    Nov 07, 2016 @ 12:52
    BEWD
    0

    Ahh, so simple but I couldn't work it out.

    Thanks very much Dennis

Please Sign in or register to post replies

Write your reply to:

Draft