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

$Pos % 12


Go to End


2 Posts   1288 Views

Avatar
MrChimp

Community Member, 6 Posts

27 June 2013 at 1:18am

Hello

I currently have two template files as follows:

ProjectHolder.ss:

<% control getItems() %>
  <% include ProjectBrief TopPos = $Pos%>
<% end_control %>

ProjectBrief.ss:

$TopPos

This counts up from 1. What I would like to do is to count up to 12 and then loop back to one again. Basically "$Pos % 12".

However, I can't use % in the template. I've tried creating a method on the ProjectHolder controller that returns "$this->iteratorPos % 12". This works as long as I don't call it within a control - which I need to. Calling it within a control returns nothing and calling $Top.LoopPos within a control always returns 0.

Any clues how I can do this?

Avatar
MrChimp

Community Member, 6 Posts

27 June 2013 at 1:23am

Well that was easy.

$Modulus(value, offset)