Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 76 posts 166 karma points
    Jan 28, 2012 @ 16:06
    Nicky Christensen
    0

    List items by a specific NodeTypeAlias?

    Hi guys...

    I want to list items by a specific nodetypealias, is this possible? I've tried this, however, it says that the NodeTypeAlias doesnt exist in the current context: 

    @foreach(var item in @Model.NodeById(1064).Children.Where(NodeTypeAlias == "NewsItem").Take(itemsPerPage).OrderBy("NewsDate desc"))

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Jan 28, 2012 @ 17:50
    Sebastiaan Janssen
    1

    You're almost there: 

    @foreach(var item in @Model.NodeById(1064).Children.Where("NodeTypeAlias == @0", "NewsItem").Take(itemsPerPage).OrderBy("NewsDate desc"))

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 29, 2012 @ 11:28
    Jeroen Breuer
    1

    Won't this also work?

    @foreach(var item in @Model.NodeById(1064).NewsItem.Take(itemsPerPage).OrderBy("NewsDate desc"))

    Think it than only uses children which are of type "NewsItem". It's a little bit shorter.

    Jeroen

  • J 150 posts 489 karma points
    Jan 29, 2012 @ 15:37
    J
    1

    Both @seb's approach and @jeroen's aproach are correct, but I do prefer the second one just because is shorter and easier to read. There's a third option that is to "pluralize" the node type alias, like this:

    @foreach(var item in @Model.NodeById(1064).NewsItems.Take(itemsPerPage).OrderBy("NewsDate desc"))
    
  • Rodion Novoselov 694 posts 859 karma points
    Jan 30, 2012 @ 01:57
    Rodion Novoselov
    0

    The matter of taste, as for me pluralising/singularising look a bit far too smart - I wonder how the nouns like "mouse", "goose", "sheep", "pants", etc would read  in this case :-)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies