Copied to clipboard

Flag this post as spam?

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


  • Kerri Mallinson 113 posts 497 karma points
    Jun 09, 2016 @ 09:27
    Kerri Mallinson
    0

    Recursive fields

    Umbraco v7.4.2 / Archetype v1.12.3

    Hi,

    I have a partial view which shows news items on a page, i'd like to use this same partial on the page's children, how can I make it recursive to pull the news items from the parent - or is there a better way?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Archetype.Models;
    @using Archetype.Extensions;
    
    @if (Model.Content.GetPropertyValue<ArchetypeModel>("news").Any())
    {
        <ul id="tape">
            @foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("news"))
    {
        <li>
            <span>@fieldset.GetValue("date") -</span>
            @if (fieldset.HasValue("link"))
            {
                <a href="@fieldset.GetValue("link")"> @fieldset.GetValue("title")</a>
            }
            else
            {
                @fieldset.GetValue("title")
            }
            </li>
        }
    </ul>
    }
    

    Any help would be greatly appreciated.

    Thanks Kerri

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jun 09, 2016 @ 09:55
    Dennis Adolfi
    100

    Hi Kerri.

    The second parameter to GetPropertyValue(string alias, bool recurse) might help you? So if you change your code to:

    @if (Model.Content.GetPropertyValue<ArchetypeModel>("news", true).Any())
    {
        <ul id="tape">
            @foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("news", true))
    {
        <li>
            <span>@fieldset.GetValue("date") -</span>
            @if (fieldset.HasValue("link"))
            {
                <a href="@fieldset.GetValue("link")"> @fieldset.GetValue("title")</a>
            }
            else
            {
                @fieldset.GetValue("title")
            }
            </li>
        }
    </ul>
    }
    

    Above code is not tested, just a thought...

  • Kerri Mallinson 113 posts 497 karma points
    Jun 09, 2016 @ 10:00
    Kerri Mallinson
    1

    Thanks Dennis,

    Was having one of those moments! - i'd tried ("news"),true !

    Cheers Kerri

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jun 09, 2016 @ 10:03
    Dennis Adolfi
    0

    Great Kerri!! Glad it worked for you!!!

    Have a great day and best of luck with the rest of your site!!

    All the best!

    / Dennis

Please Sign in or register to post replies

Write your reply to:

Draft