Copied to clipboard

Flag this post as spam?

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


  • Toni Becker 146 posts 425 karma points
    Jul 29, 2011 @ 11:56
    Toni Becker
    0

    Count Elements and give Class * 4.7.1 MacroEngines

    Okay here's the problem. I've layouted new design and for example:

    I have a postgrid with 12 elements in 3 rows (4x3)

    so i'm looping with a foreach through the items and testing with n.IsLast()) but this works only for the last node ;/

    So i have to say the code cout all and every 4th item have the class "column last" all the others class "column"

    Some advanced techniques to solve this for layout purposes.

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jul 29, 2011 @ 12:01
    Sebastiaan Janssen
    2

    You can do this a little bit like so:

    var i = 0;
    @foreach (var n in Model.Children) {
    <div class="@(i % 4 == 0 ? "column last" : "column")">
    Content
    </div>

    i++;
  • Alex 78 posts 136 karma points
    Jul 29, 2011 @ 12:02
    Alex
    1

    Check to see if the index of the item is divisible by 4?

    if ((index % 4) == 0)
    { add class } 

     

    You will probably need to use index+1 if it is a zero based array.

  • Toni Becker 146 posts 425 karma points
    Jul 29, 2011 @ 12:13
    Toni Becker
    0

    Okay thanks. Both solutions did the trick, but i have to start with i = 1 because devison of zero :p

    Thanks to you two thumbs up

  • Toni Becker 146 posts 425 karma points
    Jul 29, 2011 @ 12:17
    Toni Becker
    0

    High fived to you :)

  • 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