I have a NewsArticle node that I am trying to loop through and only list the NewsArticles with the property "selectedArticle" when selectedArticle is true. Here is my code:
Ok, I got it to work with the code below. How would I be able to sort the output using the "sort" dropdown within Umbraco's web interface? e.g. right click on the News Article node and select "sort"
The code you've used is mixing the two schemas - here's a tidied version using a variable to avoid duplicated XPaths (the path you use in the if statement should be the same you use in the for-each, otherwise you can easily get unexpected results):
EDIT: I see you found the schema-bug in the original if statement - that's what I was referring to; Apparently I was writing this while you were posting the second question :-)
Thanks, but I need the descendants of the NewsCategory[3]. Sorry, I didn't include that in my previous messages. And never mind the sorting- figured it out.
You should still create a variable for the nodes - because what you're doing now can give you unexpected results; In the if statement you're checking if any of the children have the selectedArticle property checked, but then in the for-each, you're using the descendant:: axis - to avoid having to remember to duplicate the XPath, put it in a variable straight away.
The bonus to that is also that you can perform a simple boolean test on that variable (which is in fact a nodeset - even if it's an empty one) to test whether there's any nodes - an empty nodeset will return false().
So (the double-slash // is a shortcut for descendant::):
Test for Doctype property equals "true"
I have a NewsArticle node that I am trying to loop through and only list the NewsArticles with the property "selectedArticle" when selectedArticle is true. Here is my code:
Ok, I got it to work with the code below. How would I be able to sort the output using the "sort" dropdown within Umbraco's web interface? e.g. right click on the News Article node and select "sort"
Hi Steve,
The code you've used is mixing the two schemas - here's a tidied version using a variable to avoid duplicated XPaths (the path you use in the if statement should be the same you use in the for-each, otherwise you can easily get unexpected results):
/Chriztian
EDIT: I see you found the schema-bug in the original if statement - that's what I was referring to; Apparently I was writing this while you were posting the second question :-)
Steve,
I'm not sure what you mean regarding the sort thing - could you elaborate? Do you want to sort the nodes in the backoffice?
/Chriztian
Chriztian,
Thanks, but I need the descendants of the NewsCategory[3]. Sorry, I didn't include that in my previous messages. And never mind the sorting- figured it out.
Okay - no worries:-)
You should still create a variable for the nodes - because what you're doing now can give you unexpected results; In the if statement you're checking if any of the children have the
selectedArticle
property checked, but then in the for-each, you're using thedescendant::
axis - to avoid having to remember to duplicate the XPath, put it in a variable straight away.The bonus to that is also that you can perform a simple boolean test on that variable (which is in fact a nodeset - even if it's an empty one) to test whether there's any nodes - an empty nodeset will return
false()
.So (the double-slash
//
is a shortcut fordescendant::
):BTW: If you're sorting them manually in the backoffice, you can skip the for-each and just apply templates directly using the same position predicate:
/Chriztian
Cool! Here is what I've got now, and it seems to be working! Thanks Chriztian!
is working on a reply...