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

Assigning a Variable or Previous Elements in Control Loops


Go to End


1827 Views

Avatar
Vegas Rob

Community Member, 5 Posts

8 May 2010 at 6:32am

Hi. I'm fairly new to SilverStripe and I seem to have come across my first roadblock.

I'm returning a DataObjectSet from a method in my controller that contains a set of school events sorted by date.

Printing out these items via the control loop is very simple, but the layout the designers call for has the date as a heading and then all the events for that day printed beneath it.

In other templating languages I'd normally assign a variable each iteration that contains the date of the previous event. That way I can check and see if I need to print a new header with the new date or not. Some times there is even some sort of "previous element" functionality built into the loops. Do either of these solutions, or another view based one, exist in SilverStripe?

FYI, I've solved the issue by iterating through the object in the controller method and assigning a printHeader value to true or false for each DataObject, but I am curious if this is the "SilverStripe way" or if there is a better option I am missing.

Thanks in advance for your time!