Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

modulus not working in if condition?!


Go to End


5 Posts   3270 Views

Avatar
therealhoudini

Community Member, 3 Posts

22 January 2012 at 9:01am

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

Avatar
Willr

Forum Moderator, 5523 Posts

22 January 2012 at 10:17pm

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

Avatar
therealhoudini

Community Member, 3 Posts

22 January 2012 at 10:38pm

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

Avatar
rodolfocartas

Community Member, 2 Posts

31 May 2012 at 3:25pm

Same problem with me.

Avatar
Willr

Forum Moderator, 5523 Posts

31 May 2012 at 5:34pm

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 %>