Copied to clipboard

Flag this post as spam?

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


  • Michael Brydebøl 12 posts 32 karma points
    Mar 19, 2013 @ 08:00
    Michael Brydebøl
    0

    Style first/newest item different from the other ones

    Hi

    I'm building a news list and need to style the first item/newest item different from the other ones. The items have all the same doctype.

    How do I do that with razor?

    I think I should make a for each loop but how to pick out the first item?

    Another thing.
    I have some items with a doctype and only need to show the first item/newest item - right now I have used .Take(1) and a for each loop but there should be a more smarter way to do it - right? :)

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 19, 2013 @ 08:26
    Fuji Kusaka
    0

    Hi Michael,

    What you could do is if you are making use of NodeById to get your news Items from a particular folder

    var news = Model.NodeById(1105);

     foreach(dynamic n in news.Children.Where("Visible").Where("NodeTypeAlias == \"docType\"").OrderBy("createDate  desc")){

    <li class="@Library.If(n.IsFirst(), "newest" ,"others")">
    <a href="@n.Url">@n.Name</a>
    </li> 
    }

    and to reply to your other question just add .Take(1)

    foreach(dynamic n in news.Children.Where("Visible").Where("NodeTypeAlias == \"docType\"").OrderBy("createDate  desc").Take(1)){ }

    Hope this helps

     

    fuji//

  • Carsten Fallesen 35 posts 154 karma points
    Mar 19, 2013 @ 08:29
    Carsten Fallesen
    0

    Hi,

    To do something different use the .IsFirst() method. This is documented here 

    To get the first item you simply use .First(), which is documented here.

    in general there is a lot of good documentation on the use of dynamic nodes is this part of the documentation.

    /Carsten

     

     

Please Sign in or register to post replies

Write your reply to:

Draft