Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Apr 11, 2014 @ 11:59
    Claushingebjerg
    0

    IsModZero start from node other than 1

    I need to add a class to node number 3 6 9.. and so on in a list

    Example:

    <p style="background-color:@page.IsModZero(3, "red","blue")"></p>

    But this applies to node number 1,4,7...

    How du i push the mod back or forward?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 11, 2014 @ 16:25
    Jan Skovgaard
    0

    Hi Claus

    How many items are i your list? Isn't it a matter of adjusting the number? What happens if you change it to 5?

    /Jan

  • Claushingebjerg 939 posts 2574 karma points
    Apr 11, 2014 @ 16:33
    Claushingebjerg
    0

    The number of items in the list shouldnt matter

    Example (with bold), It want this:

    node
    node
    node
    node
    node
    node
    node
    node
    node 

    but the above code does this:
    node
    node
    node 
    node
    node
    node
    node
    node
    node 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 11, 2014 @ 16:37
    Jan Skovgaard
    0

    Hi Claus

    Yes you're right about that. But what happens if you change the number to something else? What happens if you change i to 5? Does it then match every 5th node or what does it match?

    /Jan

  • Claushingebjerg 939 posts 2574 karma points
    Apr 11, 2014 @ 19:43
    Claushingebjerg
    0

    Changing 

    <pstyle="background-color:@page.IsModZero(5,"red","blue")"></p>
    applies it to node no. 1,6,11,16 and so on
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 12, 2014 @ 10:51
    Jan Skovgaard
    0

    Hi Claus

    Ok...perhaps this is a bug with the implementation? (Of the method in Umbraco, not the way you use it) Think you should try and file an issue at http://issues.umbraco.org/issues

    /Jan

  • Matt Kemp 9 posts 64 karma points
    Apr 08, 2016 @ 10:01
    Matt Kemp
    1

    I just found this and was about to create an issue for it as it seems like a pretty obvious flaw in the IsModZero method (it's not much use for modulus > 2).

    However in trying to think of what you'd name a helper method that returned the index, I realised there is a GetIndex() method already.

    So this might save someone some time in the future:

    foreach (var v in blah.Children()) {
        @Umbraco.If((v.GetIndex() +1 ) % 3 == 0,"do thing")
    }
    

    The offset is the +1 - that's how you can move it.

    It's just doing our own Mod.

  • 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