Get and store values of a multi-node tree picker into a list for filtering?
I'm trying to filter a list of displayed blog pages by categories, which are chosen via a multi-node tree picker in Umbraco on each blog page, but I'm unable to retrieve and store the values from the multi-node tree picker into a list that can be compared to the selected category.
Any attempt to get and store the values results in the content rendering as something along the lines of
The only documentation for the multi-node tree picker is the following:
var typedMultiNodeTreePicker = Model.Value<IEnumerable<IPublishedContent>>("featuredArticles");
foreach (var item in typedMultiNodeTreePicker)
{
<p>@item.Name</p>
}
which is fine for displaying content, but I can't use it to store content for later use. I've tried creating an empty list of strings and foreach looping @item.Name into them, but I still get "System" results instead of actual results. Same with attempting to store nodes into a list, integers (node IDs) into a list, etc.
I'm not familiar enough with MVC to know what I might be doing wrong.
Say your filter category is an IPublishedContent variable called filterCategory then you should be able to compare it to see if it's in the list of IDs for the property on your blog post that stores the categories.
I don't know what your models or doc types look like so you'll need to adjust this, but you can do something like this... (it assumes each blog post has a categories property that is the MNTP that returns a list of the selected categories):
IEnumerable<IPublishedContent> blogPosts; // your list of all blog posts you have populated
IPublishedContent filterCategory; // the category you want to filter the list by
var filteredPosts = blogPosts.Where(p => p.GetPropertyValue<IEnumerable<IPublishedContent>>("categories").Select(c => c.Id).Contains(filterCategory.Id));
Basically what this does is check if the filterCategory ID is contained within the list of Ids selected for the blog post.
Get and store values of a multi-node tree picker into a list for filtering?
I'm trying to filter a list of displayed blog pages by categories, which are chosen via a multi-node tree picker in Umbraco on each blog page, but I'm unable to retrieve and store the values from the multi-node tree picker into a list that can be compared to the selected category.
Any attempt to get and store the values results in the content rendering as something along the lines of
The only documentation for the multi-node tree picker is the following:
which is fine for displaying content, but I can't use it to store content for later use. I've tried creating an empty list of strings and foreach looping @item.Name into them, but I still get "System" results instead of actual results. Same with attempting to store nodes into a list, integers (node IDs) into a list, etc.
I'm not familiar enough with MVC to know what I might be doing wrong.
Using Umbraco version 7.14.0.
Say your filter category is an
IPublishedContent
variable calledfilterCategory
then you should be able to compare it to see if it's in the list of IDs for the property on your blog post that stores the categories.I don't know what your models or doc types look like so you'll need to adjust this, but you can do something like this... (it assumes each blog post has a
categories
property that is the MNTP that returns a list of the selected categories):Basically what this does is check if the filterCategory ID is contained within the list of Ids selected for the blog post.
Hope that makes sense!
is working on a reply...