I have a 4 levels deep node structure, where the top most level is made of 1 root node.
What I want to do is get all nodes in the 4th level for which a certain property(ies) is true, for example:
get all 4th level nodes where nodePropertyX == true.
Now, I could do this with a for-each loop, and iterate all the items in the levels above, but I have the feeling it would be inefficient.
-
How can I do it in a better more efficient way ? Is there a way to maybe cache my dataset? (I’m returning results as a datatable) ?
-
What is the preferrable method: using C# control (.ascx) or razor script (.cshtml)?
Depending on what you want to do with those nodes, you may use razor, macros and the built-in caching abilities for macros to cache the output of the macro:
Here’s how to get all nodes at the 4th level from the root node having a property nodePropertyX which equals value :
Place this code in a Scripting file (Section Developer, node Scripting Files), create a macro using this scripting file, and insert the macro wherever (on any template) you want to display the list of those nodes.
In order to cache the output of the macro, select the macro and set the appropriate properties (Cache Period, Cache By Page and Cache Personalized).