Copied to clipboard

Flag this post as spam?

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


  • Andrew Unger 45 posts 148 karma points
    May 11, 2020 @ 19:37
    Andrew Unger
    0

    Rendering related links that are nested content within an archtype

    I have a simple archetype that has a link using related link and an image from a media picker. I am not sure how to render that link. I have tried different ways to get it to render with no luck. This current attempt doesn't give an error but it will render this "Umbraco.Web.Models.RelatedLinks" for each of the links. This is what renders that out "@item.GetPropertyValue("houseLink")". Any help would be appreciated thank you!

        <ul class="accordion" data-accordion data-allow-all-closed="true">
            @if(node.HasValue("housePod")){
                var items = node.GetPropertyValue<IEnumerable<IPublishedContent>>("housePod");
                var count = 1;
                foreach(var item in items){  
                    <li class="accordion-item" data-accordion-item>
                    <a href="#" class="accordion-title"><div class="orangeCircle">@count</div>
                    <u>@item.GetPropertyValue("houseLink")</u>
                    </a>
                    <div class="accordion-content" data-tab-content >
                    @if(item.HasValueImage("houseImage"))
                    {
                        var image = item.GetPropertyValue<IPublishedContent>("houseImage");
                        if(image != null){
                            <img src="@image.Url" alt="image">                    
                        }
                    }
                    </div>
                      </li> 
                    count++;
                }
            }    
        </ul>
    
  • Andrew Unger 45 posts 148 karma points
    May 12, 2020 @ 13:03
    Andrew Unger
    0

    I ended up having to use a foreach loop to access the related link I have. I have related links to only allow for 1 link but it looks like you still have to use a foreach loop to access the links. Bassically I added this line "var links = item.GetPropertyValue

            <ul class="accordion" data-accordion data-allow-all-closed="true">
                @if(node.HasValue("housePod")){
                    var items = node.GetPropertyValue<IEnumerable<IPublishedContent>>("housePod");
                    var count = 1;
                    foreach(var item in items){
                    var links = item.GetPropertyValue<RelatedLinks>("houseLink");
                        <li class="accordion-item" data-accordion-item>
                        <a href="#" class="accordion-title"><div class="orangeCircle">@count</div>
                            @foreach(var link in links){
                            <u>@link.Caption</u>
                            }
                        </a>
                        <div class="accordion-content" data-tab-content >
                        @if(item.HasValueImage("houseImage"))
                        {
                            var image = item.GetPropertyValue<IPublishedContent>("houseImage");
                            if(image != null){
                                <img src="@image.Url" alt="image">                    
                            }
                        }
                        </div>
                          </li> 
                        count++;
                    }
                }    
            </ul>
    
Please Sign in or register to post replies

Write your reply to:

Draft