I have a 'story category' document type and a 'story' document type. Users can attach story categories to created stories via Contentful Data List property name 'categories'.
I'm outputting these stories via a Block Grid element. By default, all stories will show up. But if the url has a query parameter (Ex: ?cat=url-segment), then I'd like to output a filtered view where the 'cat' parameter matches stories that have story category with a matching UrlSegment. I'm not receiving any errors, but nothing is outputting however when I using the following code.
I'm brand new to Umbraco and .net core, so I appreciate what a great resource this community has been so far.
If I use the story category ID as the cat parameter instead of UrlSegment and change the code to the following, it works. But I would prefer to match by UrlSegment if possible.
filtering nodes by UrlSegment instead of ID
I have a 'story category' document type and a 'story' document type. Users can attach story categories to created stories via Contentful Data List property name 'categories'.
I'm outputting these stories via a Block Grid element. By default, all stories will show up. But if the url has a query parameter (Ex: ?cat=url-segment), then I'd like to output a filtered view where the 'cat' parameter matches stories that have story category with a matching UrlSegment. I'm not receiving any errors, but nothing is outputting however when I using the following code.
I'm brand new to Umbraco and .net core, so I appreciate what a great resource this community has been so far.
If I use the story category ID as the cat parameter instead of UrlSegment and change the code to the following, it works. But I would prefer to match by UrlSegment if possible.
Hi utiilityLA
When you have the working filtering your code is
Select(y=>y.Id)
this would result in an IEnumerable of Ids
and your contains clause checks if it contains the current Id
...
but in your example for UrlSegment
you have
.Select(y => y.UrlSegment)
wouldn't that result in an IEnumerable of strings for each UrlSegment?
and so that would never equal a string category?
also wondering if Any is what you need? I'm typing this on a phone but something like this:
regards
marc
Thanks Mark for your response. It makes sense that an IEnumerable of strings would not match a single string.
Your suggestion of using "Any" worked great! Thank you for pointing me in the right direction.
is working on a reply...