Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Dec 21, 2017 @ 04:14
    blackhawk
    0

    How to render Related Links from within Nested Content

    I read the documentation on Related Links 2.

    I have a fresh install of Umbraco 7.7.2, using Models Builder in Dll mode, and using the following statements on my home template...

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Home> @using Umbraco.Web.Models

    On my content node, my related link property is populated. I have 7 different links.

    I then attempted to add the following logic to my razor template...

       @{
                var typedRelatedLinksConverted = Model.GetPropertyValue<RelatedLinks>("socialMenuBar");
    
                if (typedRelatedLinksConverted != null && typedRelatedLinksConverted.Any())
                {
                    <ul>
                        @foreach (var item in typedRelatedLinksConverted)
                        {
                            var linkTarget = (item.NewWindow) ? "_blank" : null;
                            <li><a href="@item.Link" target="@linkTarget">@item.Caption</a></li>
                        }
                    </ul>
                }
                else
                {
                    <p>nothing here</p>
                }
            }
    

    ...But the browser keeps showing nothing here when I render the page.
    It's as though 'socialMenuBar' doesn't even exist. But that is the name of my property alias. What things should I check to fix this issue?

    Thanks for any tips

  • blackhawk 313 posts 1368 karma points
    Dec 21, 2017 @ 05:00
    blackhawk
    100

    After getting some sleep, I discovered a solution to my main problem...how to render related links from within nested content. The following code helped me....

    <section>
            @{
                var msocialMenuBar = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("socialMenuBar");
    
                if (msocialMenuBar != null && msocialMenuBar.Any())
                {
                    <ul>
                        @foreach (var item in msocialMenuBar)
                        {
                            <li>
                                <span>@item.Name</span>
    
                                @if(item.HasValue("footerSocialLink"))
                                {
                                    foreach (var mlink in item.GetPropertyValue<RelatedLinks>("footerSocialLink"))
                                    {
                                        <p>@mlink.Caption | @mlink.Link</p>
                                    }
                                }
                            </li>
                        }
                    </ul>
                }
            }
        </section>
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies