Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 893 posts 2442 karma points
    Apr 10, 2015 @ 15:20
    Claushingebjerg
    0

    Listing nodes of multiple doc types

    Im trying to list sub nodes of specific doc types. I got this:

    @{
      var homePage = CurrentPage.AncestorsOrSelf(2).First();
      var subItems = homePage.Children.Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "Personliste", "Tekstside").ToList();
    }
    
    <ul class="under_menu">
      @foreach (var item in subItems) {
        <li><a href="@item.Url">@item.Name</a></li>
      }
    </ul> 

     

    But his will only render the first declared doc type, here "Personliste". I dont really get why that is...

  • Dennis Aaen 4466 posts 17999 karma points admin hq c-trib
    Apr 10, 2015 @ 16:24
    Dennis Aaen
    100

    Hi Claus,

    What if you do something like this would this work ?.

    var subItems = homePage.Children.Where("DocumentTypeAlias == @0 || DocumentTypeAlias == @1", "Personliste", "Tekstside").ToList();

    I can see from the code that you are not using the old legacy Razor,

    Hope this helps,

    /Dennis

  • Claushingebjerg 893 posts 2442 karma points
    Apr 10, 2015 @ 20:45
    Claushingebjerg
    0

    Yes, that works.

    But why Does my example (lifted from another thread) not work?

    Whats the difference between NodeTypeAlias and DocumentTypeAlias?
    Is NodeTypeAlias deprecated? 

  • Jan Skovgaard 11259 posts 23501 karma points MVP 8x admin c-trib
    Apr 10, 2015 @ 20:53
    Jan Skovgaard
    0

    Hi Claus

    Just to chime in - I don't know if you have seen the Razor cheatsheet for v6 - It works for v7 too. You can find it here https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets - As you can see there is no "NodeTypeAlias" option in there.

    I don't know if it was implemented like this in previous versions of the Razor implementation in Umbraco though but since you're coming from an XSLT background you have probably been using the @nodeTypeAlias attribute a lot previously, which may be the reason why you tried calling it the same in Razor? I know I still tend to do that myself since it's confusing that it's now called something else :)

    /Jan

  • Claushingebjerg 893 posts 2442 karma points
    Apr 13, 2015 @ 09:04
    Claushingebjerg
    0

    Lol, i actually got it from a post from Dennis himself... :)
    (im not going to link to it, since it aparrently not correct any more)

    What makes me confused though, is that NodeTypeAlias "sort of" works... It doesn't fail completely, but doesnt work as expected... That must throw a lot of people. I'm gonna download the cheat sheets again :). I had them printed out earlier as a reference on my desk, but they have gone missing :).

  • Dennis Aaen 4466 posts 17999 karma points admin hq c-trib
    Apr 13, 2015 @ 09:52
    Dennis Aaen
    0

    Hi Claus,

    The example you are refers to where Clare need to listing nodes of multiple doc types uses the old DynmaicNode Razor, and I think the DocumentTypeAlias is introduced when you are using partial view macros or parial views. Can´t remember if it´s only when you are using Umbraco 7

    Hope this helps,

    /Dennis

  • Claushingebjerg 893 posts 2442 karma points
    Apr 13, 2015 @ 10:33
    Claushingebjerg
    0

    Glad to see im not the only one who's a bit unsure :)

  • keilo 563 posts 1018 karma points
    Aug 29, 2018 @ 13:26
    keilo
    0

    Hi Claus

    Did you figure this out at the end?

    I am trying to do a similar thing and it doesnt seem to work on 2nd literal, posted full details at another post here

  • Claushingebjerg 893 posts 2442 karma points
    Aug 30, 2018 @ 06:38
    Claushingebjerg
    0

    Yeah, if you read above: NodeTypeAlias doesnt work, it should be DocumentTypeAlias

  • keilo 563 posts 1018 karma points
    Aug 30, 2018 @ 08:01
    keilo
    0

    Hi Claus

    I could swear it didnt work the first time when I tried the alternative...

    Changing to DocumentTypeAlias works indeed.

    Many thanks for taking time to reply.

Please Sign in or register to post replies

Write your reply to:

Draft