I have MNTP property editor on member profiles and i want to display picked nodes like this:
And not like this:
var member = Members.GetById(Model.MemberID);
var typedMultiNodeTreePicker = member.Value<IEnumerable<IPublishedContent>>("categoryPicker");
foreach (var item in typedMultiNodeTreePicker)
{
<p>@item.Name</p>
}
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!!!!
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>
}
}
}
How to structure MNTP values?
Hi All,
I have MNTP property editor on member profiles and i want to display picked nodes like this:
And not like this:
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
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.
Thanks
is working on a reply...