Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kim Bantz Rasmussen 81 posts 310 karma points
    Aug 12, 2012 @ 17:38
    Kim Bantz Rasmussen
    0

    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 descendantsfilter by type:
        var nodes root.Descendants("Timeline | Case");
        // Loop through the filtered nodesdisplaying the properties:
        <ul>
        @foreach (var node in nodes)
        {
            <li>
                <h2>@node.pageTitle</h2>
            </li>
        }
        </ul>
    }

    Umbraco 4.8, .NET 4.0

    Best regards
    Kim

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Aug 12, 2012 @ 20:37
    Bo Damgaard Mortensen
    0

    Hi Kim,

    What does the error say when you try to save the Razor file? :-)

  • Kim Bantz Rasmussen 81 posts 310 karma points
    Aug 13, 2012 @ 09:02
    Kim Bantz Rasmussen
    0

    Hi Bo,

    There isn't any errors - just no output.

    Am I selecting the document types the right way "Timeline | Case" ?

    Best regards
    Kim 

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Aug 13, 2012 @ 13:27
    Bo Damgaard Mortensen
    0

    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:

    var nodes = root.Descendants.Where("NodeTypeAlias = 'Timeline' or NodeTypeAlias = 'Case'");

    ? :-) Can't remember of you can pass in the "or" keyword of if it's "||" though.

    - Bo

  • Douglas Ludlow 210 posts 366 karma points
    Aug 13, 2012 @ 17:20
    Douglas Ludlow
    0

    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:

    var nodes = root.Descendants().Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "Timeline", "Case");

     

     

  • Kim Bantz Rasmussen 81 posts 310 karma points
    Aug 13, 2012 @ 17:20
    Kim Bantz Rasmussen
    0

    Hi Bo,

    Yes, I have tried your suggestion - it did not work :( But thanks for your reply!

    I have rewritten the code to this: 

    var nodes = Model.AncestorOrSelf().Descendants("Case");

    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:

    var nodes = Model.AncestorOrSelf().Descendants.Where("NodeTypeAlias == @0 or NodeTypeAlias == @1 and Visible", "Timeline", "Case");

    It did not work either, but I think I am close?

  • Douglas Ludlow 210 posts 366 karma points
    Aug 13, 2012 @ 17:22
    Douglas Ludlow
    1

    Descendents() should be a method. You forgot the parenthesis. Oh and it is definitely "||" not "or", just like a regular c# expression.

  • Kim Bantz Rasmussen 81 posts 310 karma points
    Aug 13, 2012 @ 17:24
    Kim Bantz Rasmussen
    0

    Hi Douglas,

    It worked!

    Thanks

  • Douglas Ludlow 210 posts 366 karma points
    Aug 13, 2012 @ 17:25
    Douglas Ludlow
    0

    No problemo!

  • Streety 358 posts 568 karma points
    Mar 31, 2017 @ 11:26
    Streety
    0

    This works...

    .Where(x => x.DocumentTypeAlias == "Timeline" || x.DocumentTypeAlias == "Case")   
    
Please Sign in or register to post replies

Write your reply to:

Draft