Create a timeline based on multiple document types
I would love to make a list of timeline elements based on multiple document types:
Normal timeline elements (i.e. news - new and archived) and cases.
I am very, very new to Razor, and tried to write this:
@{ // Get root node: var root = Model.AncestorOrSelf(); // Get all descendants, filter by type: var nodes = root.Descendants("Timeline | Case"); // Loop through the filtered nodes, displaying the properties: <ul> @foreach (var node in nodes) { <li> <h2>@node.pageTitle</h2> </li> } </ul> }
Create a timeline based on multiple document types
I would love to make a list of timeline elements based on multiple document types:
Normal timeline elements (i.e. news - new and archived) and cases.
I am very, very new to Razor, and tried to write this:
Umbraco 4.8, .NET 4.0
Best regards
Kim
Hi Kim,
What does the error say when you try to save the Razor file? :-)
Hi Bo,
There isn't any errors - just no output.
Am I selecting the document types the right way "Timeline | Case" ?
Best regards
Kim
Hi Kim,
Hmm, it looks fine to me, although I can't find a description of it in the documentation. Have you tried the following:
? :-) Can't remember of you can pass in the "or" keyword of if it's "||" though.
- Bo
Yeah the issue is in how you are trying to filter the descendants. The Descendants() method does not take expressions. Use the Where() method instead:
Hi Bo,
Yes, I have tried your suggestion - it did not work :( But thanks for your reply!
I have rewritten the code to this:
Which gets all my cases, so half way there, and then I saw the post: http://our.umbraco.org/forum/developers/razor/30183-Simple-Razor-Question
And wrote this:
It did not work either, but I think I am close?
Descendents() should be a method. You forgot the parenthesis. Oh and it is definitely "||" not "or", just like a regular c# expression.
Hi Douglas,
It worked!
Thanks
No problemo!
This works...
is working on a reply...