finding pages where descendants have certain property
How do I select the pages where the descendants have a certain property value.
For example I have this tree and I'd like to get only the location pages where the course type page have property value a.
-- location ---- page ------ course type with property value a -- location ---- page ------ course type with property value b
Is such a thing possible in one statement or would I need to select all the locations and loop through them then only select the ones that have the property value I want.
Yes it is, in the below example we look at properties with the alias "superHero" and get returned a collection of items where they that property has the value "SuperMan"
@{
var valueToMatch = "SuperMan";
var home = CurrentPage.AncestorOrSelf(1);
if (home != null)
{
var articles = home. Descendants.Where("superHero.ToLower() == @0", valueToMatch.ToLower());
if (articles.Any())
{
<p>Pages with @valueToMatch selected:</p>
<ul>
@foreach (var page in articles)
{
<li><a href="@page.Url"> @page.Name</a></li>
}
</ul>
}
}
}
Thanks that helps me with the syntax of the where statement.
It will give me the list of descendants though. I need a list of the higher level pages, in your example those at the home level. Think I'm going to have to loop through the location pages to do that.
finding pages where descendants have certain property
How do I select the pages where the descendants have a certain property value.
For example I have this tree and I'd like to get only the location pages where the course type page have property value a.
-- location
---- page
------ course type with property value a
-- location
---- page
------ course type with property value b
Is such a thing possible in one statement or would I need to select all the locations and loop through them then only select the ones that have the property value I want.
Hi Suzy,
Yes it is, in the below example we look at properties with the alias "superHero" and get returned a collection of items where they that property has the value "SuperMan"
Hope that's helpful?
Jeavon
Thanks that helps me with the syntax of the where statement.
It will give me the list of descendants though. I need a list of the higher level pages, in your example those at the home level. Think I'm going to have to loop through the location pages to do that.
Hi Suzy, The example will filter all descendants of the home, which would normally be your entire site. Jeavon
is working on a reply...