Copied to clipboard

Flag this post as spam?

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


  • Peter van Geffen 54 posts 290 karma points
    Oct 23, 2019 @ 13:36
    Peter van Geffen
    0

    Content from multiple properties in the same group

    Is there a more simple solution to get content from multiple properties (who have the same type of content) in the same group?

    Groupname

    • propertyOne
    • propertyTwo
    • propertyThree
    • propertyFour

    What i'm doing now is calling 4 times the content (example below)

    @{
        var typedMultiNodeTreePicker1 = Model.Value<IEnumerable<IPublishedContent>>("propertyOne");
        if (typedMultiNodeTreePicker1 != null)
        {
            foreach (var item in typedMultiNodeTreePicker1)
            {
                <p><strong>@item.Name</strong></p>
            }
        }
    }
    @{
        var typedMultiNodeTreePicker2 = Model.Value<IEnumerable<IPublishedContent>>("propertyTwo");
        if (typedMultiNodeTreePicker2 != null)
        {
            foreach (var item in typedMultiNodeTreePicker2)
            {
                <p><strong>@item.Name</strong></p>
            }
        }
    }
    @{
        var typedMultiNodeTreePicker3 = Model.Value<IEnumerable<IPublishedContent>>("propertyThree");
        if (typedMultiNodeTreePicker3 != null)
        {
            foreach (var item in typedMultiNodeTreePicker3)
            {
                <p><strong>@item.Name</strong></p>
            }
        }
    }
    @{
        var typedMultiNodeTreePicker4 = Model.Value<IEnumerable<IPublishedContent>>("propertyFour");
        if (typedMultiNodeTreePicker4 != null)
        {
            foreach (var item in typedMultiNodeTreePicker4)
            {
                <p><strong>@item.Name</strong></p>
            }
        }
    }
    
  • Jonathan Distenfeld 105 posts 618 karma points
    Oct 24, 2019 @ 08:26
    Jonathan Distenfeld
    100

    Hi,

    I believe there is no better way to receive the properties, but you could handle them more nicely in the view:

    @{
    var allTreePickers = new List<IPublishedContent>();
    allTreePickers.AddRange(Model.Value<IEnumerable<IPublishedContent>>("propertyOne"));
    allTreePickers.AddRange(Model.Value<IEnumerable<IPublishedContent>>("propertyTwo"));
    allTreePickers.AddRange(Model.Value<IEnumerable<IPublishedContent>>("propertyThree"));
    allTreePickers.AddRange(Model.Value<IEnumerable<IPublishedContent>>("propertyFour"));
    if (allTreePickers.Any())
    {
        foreach (var item in allTreePickers)
        {
            <p><strong>@item.Name</strong></p>
        }
    }
    }
    

    ~ Jonathan

  • Peter van Geffen 54 posts 290 karma points
    Oct 24, 2019 @ 13:18
    Peter van Geffen
    0

    Thanks. This works great for me! :) As a newbie I would not have figured that out.

Please Sign in or register to post replies

Write your reply to:

Draft