Copied to clipboard

Flag this post as spam?

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


  • Silvija 58 posts 171 karma points
    Jun 21, 2019 @ 20:01
    Silvija
    0

    How to structure MNTP values?

    Hi All,

    I have MNTP property editor on member profiles and i want to display picked nodes like this:

    enter image description here

    And not like this:

    enter image description here

    var member = Members.GetById(Model.MemberID);
                    var typedMultiNodeTreePicker = member.Value<IEnumerable<IPublishedContent>>("categoryPicker");
                    foreach (var item in typedMultiNodeTreePicker)
                    {
                        <p>@item.Name</p>
                    }
    
  • Marc Goodson 1695 posts 11278 karma points MVP 7x c-trib
    Jun 22, 2019 @ 20:50
    Marc Goodson
    1

    Hi Silvija

    I wonder if you could use the following information to your advantage? :-)

    Each picked IPublishedContent item will have a 'Level' property, this indicates how 'deep' it is in the content tree, so if you write out the @item.Level property you'll get to see which level each of your picked items have, and could perhaps use this value to group picked items together, to build your hierachy, eg loop through all the picked items with Level 1, to write out the top level items in your tree structure...

    Now second useful thing, is each IPublishedContent item also has a Path property... this is a comma delimited string of all the ids of the ancestors of all the items above the picked item in the content tree... eg

    -1,123,3333,55555

    would be the path for an item with Id, 55555, having a parent with id 3333 and grandparent 123, finally -1 representing the root of the site...

    So wondering if you could use this info to see if a picked item, actually belonged underneath another picked item, because it's path would contain the id of the other picked item...

    I'm not super sure if I understand what you are trying to do! but I'm thinking the above two bits of information will help you achieve it!!!!

    regards

    Marc

  • Silvija 58 posts 171 karma points
    Jun 24, 2019 @ 11:49
    Silvija
    0

    Hi Marc, I have used level property without path, It looks a bit messy , can you suggest me some improvements, I am sure it could be much more simple than this.

    @{
    var member = Members.GetById(Model.MemberID);
    var memberCategories = member.Value<IEnumerable<IPublishedContent>>("categoryPicker");
    }
            <div id="accordion" class="py-3">
                                        @foreach (var category in memberCategories.Where(x => x.Level == 3))
                                        {
                                            <div class="card mb-1 rounded-0">
    
                                                <a class="btn-light btn-block btn-sm btn rounded-0" data-toggle="collapse" href="#@(category.Name.ToUrlSegment()+ category.Id)">
                                                    @(category.Name.ToUrlSegment() + category.Id) @category.Level , @category.Path
                                                </a>
    
                                                <div id="@(category.Name.ToUrlSegment()+ category.Id)" class="collapse" data-parent="#accordion">
                                                    <div class="card-body py-0 pl-5 pr-0">
                                                        @{
                                                            var children = memberCategories.Where(x => x.Level >= 4 && x.Parent == category).ToArray();
                                                            if (children.Length > 0)
                                                            {
                                                                @* Call our helper to display the children *@
                                                                @ChildPages(children, category.Level, category.Id)
                                                            }
                                                        }
                                                    </div>
                                                </div>
                                            </div>
                                        }
                                    </div>
            @helper ChildPages(IPublishedContent[] selection, int itemLevel, int itemID)
            {
                if (selection.Length > 0)
                {
                    foreach (var item in selection.Where(x => x.Level == itemLevel + 1 && x.Parent.Id == itemID))
                    {
                        <a class="btn-light btn-block btn-sm btn rounded-0 my-1" data-toggle="collapse" href="#@(item.Name.ToUrlSegment() + item.Id)">
                            @(item.Name.ToUrlSegment() + item.Id) @item.Level
                        </a>
                        <div id="@(item.Name.ToUrlSegment()+ item.Id)" class="collapse" data-parent="#@(item.Parent.Name.ToUrlSegment() + item.Parent.Id)">
                            <div class="card-body py-0 pl-5 pr-0">
                                @{
                                    int level = item.Level;
                                    var children = item.Children.Where(x => x.Level == item.Level + 1 && x.Parent == item).ToArray();
                                    if (children.Length > 0)
                                    {
                                        @* Recurse and call our helper to display the children *@
                                        @ChildPages(children, item.Level, item.Id)
                                    }
                                }
                            </div>
                        </div>
                    }
                }
            }
    

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft