Jump to:

3395 Posts in 977 Topics by 853 members

Template Questions

SilverStripe Forums » Template Questions » modulus not working in if condition?!

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 918 Views
  • therealhoudini
    Avatar
    Community Member
    3 Posts

    modulus not working in if condition?! Link to this post

    hi there!

    in SS 2.4 there is a new template function "modulus", but it doesn't work with if condition, any ideas?

    example: $modulus(3) returns an integer, but <% if $modulus(3) == 1 %>do something <% end_if %> doesn't work

    thx!
    houdini

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: modulus not working in if condition?! Link to this post

    You have to use <% if MultipleOf(2) %> in that case for 2.* at least

  • therealhoudini
    Avatar
    Community Member
    3 Posts

    Re: modulus not working in if condition?! Link to this post

    Hi Willr,

    thank you for your fast answer!

    It's working in a single condition, but if you try something like that:

    <% if MultipleOf(2) %>
    foo2
    <% else_if MultipleOf(3) %>
    foo3
    <% else %>
    foo4
    <% end_if %>

    it only outputs:

    foo4 foo2 <% else_if MultipleOf(3) %> foo3 foo4 foo2 <% else_if MultipleOf(3) %> foo3

    Greetings
    Houdini

  • rodolfocartas
    Avatar
    Community Member
    2 Posts

    Re: modulus not working in if condition?! Link to this post

    Same problem with me.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: modulus not working in if condition?! Link to this post

    The 2.* template engine is nice and stupid so you'll need to do something like

    <% if MultipleOf(2) %>
    foo2
    <% else %>
    <% if MultipleOf(3) %>
    foo3
    <% else %>
    foo4
    <% end_if %>
    <% end_if %>

    918 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.