Copied to clipboard

Flag this post as spam?

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


  • Magnus Szatkowski 28 posts 149 karma points
    Dec 21, 2016 @ 13:42
    Magnus Szatkowski
    0

    MultiNodeTreepicker - displaying links to subpages in a footer

    Hi guys!

    Merry Christmas!

    I have a small problem atm. I am trying to display a list of links, which has been selected from a MultiNode Treepicker.

    The content is tied up to my master file, so i can access it from all over my website, but i can't get the MultiNode Treepicker to show med the correct result. My code looks like this:

    <footer>
    <div>
        @{ var page = Umbraco.Content(1069);
          if (page.HasValue("nyttigeLinks"))
        {var bannerListValue = page.GetPropertyValue("nyttigeLinks");
        var bannerList = bannerListValue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var bannerCollection = Umbraco.TypedContent(bannerList).Where(x => x != null);
        foreach (var item in bannerListValue)
        {
            <p>@item</p>
        }
    }
        <adress class="col-md-3">
            <h3>IT-Hotellet</h3>
            <ul>
                <li><strong>Kontor</strong>: @page.GetPropertyValue("kontorAdresse")  </li>
                <li><strong>Bunkeren</strong>: @page.GetPropertyValue("bunkerAdresse")</li>
                <li><strong>Telefon</strong>: @page.GetPropertyValue("telefon")</li>
                <li><strong>Mail</strong>: <a href="mailto:@page.GetPropertyValue("email")">@page.GetPropertyValue("email")</a></li>
            </ul>
        </adress>
        <section class="col-md-3">
            <h3>Nyttige Links</h3>
    
            <ul>
                <li><a href="#">Handelsbetingelser</a></li>
                <li><a href="/">Forside</a></li>
                <li><a href="#">Kontakt os</a></li>
                <li><a href="#">Om IT-Hotellet</a></li>
            </ul>
        </section>
        }
    

    I want it to display my list of "nyttige links" in the "Nyttige Links" section.

    Can anyone help me?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 21, 2016 @ 23:17
    Dennis Aaen
    0

    Hi Magnus,

    I had a look at your code. Could you please try using this code below.

    @{
        var page = Model.Content.AncestorOrSelf(1);
        if (page.HasValue("nyttigeLinks"))
        {
            var bannerListValue = page.GetPropertyValue<string>("nyttigeLinks");
            var bannerList = bannerListValue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var bannerCollection = Umbraco.TypedContent(bannerList).Where(x => x != null);
            foreach (var item in bannerCollection)
            {
                <p>@item.Name</p>
            }
        }
    }
    

    I would recommend you not to code against Id´s in Umbraco if possible for you, the reason for this is that the Id can change if people are deleting the node and re-created it then it will get another id.

    What I have done is using the var page = Model.Content.AncestorOrSelf(1);which means that you to the the top of your content tree which would be the homepage node.

    It can be necessary for you to change this depending on how your content tree structure looks like.

    Hope this helps,

    /Dennis

  • Magnus Szatkowski 28 posts 149 karma points
    Dec 28, 2016 @ 12:41
    Magnus Szatkowski
    0

    Hi Dennis,

    Thank you for your every helping nature and your repsonse!

    When i try to use the Model.Content.AncestorOrSelf(1); i get this compliation error:

    CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Content' and no extension method 'Content' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    And when i dont use it i get this error:

    CS1976: Cannot use 'Parse' as an argument to a dynamically dispatched operation because it is a method group. Did you intend to invoke the method?

    Can you help with any of this?

    Merry Christmas by the way! :)

    /Magnus

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 28, 2016 @ 13:00
    Dennis Aaen
    0

    Hi Magnus,

    Merry Christmas to you too. Could you please try this code below and see if it works for you.

    @{
        var page = CurrentPage.AncestorOrSelf(1);
        if(page.HasValue("nyttigeLinks")){
        var bannerList = CurrentPage.nyttigeLinks.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var bannerCollection = Umbraco.Content(bannerList);
            foreach (var item in bannerCollection)
            {
                <p>@item.Name</p>
            }
    
        }
    }
    

    Hope this helps,

    /Dennis

  • Magnus Szatkowski 28 posts 149 karma points
    Jan 06, 2017 @ 08:22
    Magnus Szatkowski
    0

    Hey Dennis,

    Now i am on the other side of christmas and new years.

    I can get this to work - however, what i need this list to do, is to work as links. Would that be possible?

    Kind regards, Magnus

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 06, 2017 @ 10:31
    Dennis Aaen
    100

    Hi Magnus,

    Hope you had a great Christmas and new year.

    Sure, then you need to do like this. Then you should get links with the url to the page.

    @{
        var page = CurrentPage.AncestorOrSelf(1);
        if(page.HasValue("nyttigeLinks")){
        var bannerList = CurrentPage.nyttigeLinks.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var bannerCollection = Umbraco.Content(bannerList);
            foreach (var item in bannerCollection)
            {
                <a href="@item.Url">@item.Name</a>
            }
    
        }
    }
    

    Hope this helps,

    /Dennis

  • Magnus Szatkowski 28 posts 149 karma points
    Jan 06, 2017 @ 12:17
    Magnus Szatkowski
    0

    Thank you very much Dennis!

    It works now :)

    Kind regards, Magnus

Please Sign in or register to post replies

Write your reply to:

Draft