Copied to clipboard

Flag this post as spam?

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


  • Andy 9 posts 99 karma points
    Sep 03, 2020 @ 10:39
    Andy
    0

    Rendering Multi URL Picker inside Nested Content

    Hi,

    Im working on an Umbraco 8.3 project where I need some editable links in the footer of a page. The links need to be sorted into grouped columns.

    I've set up the group part of it using Nested Content, but i'm having issues getting the links out.

    Here is what I have so far,

    @if (Model.Root().HasValue("footerLinks"))
        {
            <div class="row">
                @{
                    var items = Model.Root().Value<IEnumerable<IPublishedElement>>("footerLinks");
                    foreach(var item in items)
                    {
    
                        <div class="col-md-3">
                            <div>@item.GetProperty("groupName").Value()</div>
    
                            @{
                                var links = item.Value<IEnumerable<Link>>("links");
                                if (links.Any())
                                {
                                    <ul>
                                        @foreach (var link in links)
                                        {
                                            <li><a href="@link.Url" target="@link.Target">@link.Name</a></li>
                                        }
                                    </ul>
                                }
                            }
    
                        </div>
    
                    }
                }
            </div>
        }
    

    It would be great if anyone had any ideas on what i'm doing wrong. Im not a developer so apologies if its something obvious!

    Thanks

  • Marc Goodson 2046 posts 13489 karma points MVP 8x c-trib
    Sep 03, 2020 @ 19:41
    Marc Goodson
    0

    Hi Andy

    Are you getting any errors? or are the links just not showing?

    Broadly what you have appears correct, or at least at a glance, I might rejiggle things around like this:

    @if (Model.Root().HasValue("footerLinks"))
        {
           var items = Model.Root().Value<IEnumerable<IPublishedElement>>("footerLinks");
    
            <div class="row">
                    @foreach(var item in items)
                    {
                         var links = item.Value<IEnumerable<Link>>("links");
    
                        <div class="col-md-3">
                            <div>@item.Value<string>("groupName")</div> 
                                @if (links.Any())
                                {
                                    <ul>
                                        @foreach (var link in links)
                                        {
                                            <li><a href="@link.Url" target="@link.Target">@link.Name</a></li>
                                        }
                                    </ul>
                                }
                        </div> 
                    }             
            </div>
        }
    

    But be good to know what is not working for you to advise further.

    regards

    Marc

  • Andy 9 posts 99 karma points
    Sep 04, 2020 @ 08:44
    Andy
    0

    Hi Marc,

    Sorry, I should have posted the error too!

    enter image description here

    I get the same error when I use your updated code too.

    Thanks for your help!

  • Marc Goodson 2046 posts 13489 karma points MVP 8x c-trib
    Sep 04, 2020 @ 15:28
    Marc Goodson
    100

    Hi Andy

    Cool we just need to tell the partial view where the definition for the Link class is coming from.

    https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/Models/Link.cs

    So if you add the namespace

    @using Umbraco.Web.Models

    to the top of your View, that particular error should go away!

    To save adding this reference at the top of every View or Partial View, if you look inside your /Views/Web.Config file there is a section for namespaces that are used in Views, and you can add Umbraco.Web.Models here...

    regards

    Marc

  • Andy 9 posts 99 karma points
    Sep 04, 2020 @ 16:26
    Andy
    0

    Doh! I knew it would be something simple.

    Thanks so much for your help!

Please Sign in or register to post replies

Write your reply to:

Draft