I have a tree 6 levels deep. I want to create an alphabetical list of bottom level nodes from any of the upper level ones. This:
@foreach (var item in Model.DescendantsOrSelf(6).OrderBy("Name"))
returns all the bottom level nodes but I'd rather filter it by document type, in case I ever stick another level on something or otherwise change it.
I thought it'd be as simple as Model.DescendantsOrSelf(Model.MyDocumentTypeName) or perhaps .Where("MyDocumentTypeName") but I guess not. I tried dinking around with .NodeTypeAlias but couldn't figure that out either.
Any tips/pointers/suggestions?an't seem to get it to filter for just the bottom level node
You are right, Dmitriy, it does work. I swear I tried that last night but maybe I missed it. Thank you.
Just to check whether I'm dumb or crazy, in other posts, I've run accross comments about Umbraco caching problems, is it possible it wasn't working last night due to something like that? And if so, is that something that can be easily checked/cleared?
Thanks much to both of you, I appreciate the suggestions and usage examples very much.
Any idea if there's a way to do a "greater than" or "less than" comparison in the where clause? Using angle brackets caused the macro to fail to load in all of the cases I tried.
@RGoodSW, you can you "greater than" and "less than" comparisons in the Where clause. It would be best if you gave an example so we could have an idea of why it's not working. Here are a couple of samples of how it should work:
var root = Model.AncestorOrSelf();
int level = 2; var collection1 = root.Descendants().Where("Level >= @0", level);
Filter list of nodes by document type
I have a tree 6 levels deep. I want to create an alphabetical list of bottom level nodes from any of the upper level ones. This:
returns all the bottom level nodes but I'd rather filter it by document type, in case I ever stick another level on something or otherwise change it.
I thought it'd be as simple as Model.DescendantsOrSelf(Model.MyDocumentTypeName) or perhaps .Where("MyDocumentTypeName") but I guess not. I tried dinking around with .NodeTypeAlias but couldn't figure that out either.
Any tips/pointers/suggestions?an't seem to get it to filter for just the bottom level node
Why this not working for you?
? Actually it should return all Descendants for current node with "YOUR DOCUMENT TYPE" document type.
Also i think you can do filtering like:
Dmitriy is correct, you should be able to filter the collection of descendants by doing:
However, using Where, you would do:
You are right, Dmitriy, it does work. I swear I tried that last night but maybe I missed it. Thank you.
Just to check whether I'm dumb or crazy, in other posts, I've run accross comments about Umbraco caching problems, is it possible it wasn't working last night due to something like that? And if so, is that something that can be easily checked/cleared?
Thanks much to both of you, I appreciate the suggestions and usage examples very much.
Any idea if there's a way to do a "greater than" or "less than" comparison in the where clause? Using angle brackets caused the macro to fail to load in all of the cases I tried.
--Bob G.
If you haven't seen it yet, according to the Razor walkthrough you can:
http://umbraco.com/follow-us/blog-archive/2011/3/1/umbraco-razor-feature-walkthrough-%E2%80%93-part-4
Cheat sheet mentions conditional filtering:
http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet
Personally, I haven't had the opportunity to try it so I can neither confirm nor deny.
@RGoodSW, you can you "greater than" and "less than" comparisons in the Where clause. It would be best if you gave an example so we could have an idea of why it's not working. Here are a couple of samples of how it should work:
is working on a reply...