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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS3: with/loop vs. control

Go to End

2 Posts   1975 Views


Community Member, 2 Posts

31 May 2012 at 11:51am

Firstly, apologies if this has already been asked or discussed but I tried to search the forum, and the keywords are pretty generic so couldn't find anything.

Having been an avid user of SS for many years, I'm surprised to see that <% control %> has been deprecated in favour or <% with %> and <% loop %> and I'm struggling to understand the reason for the change.

Unless I'm missing something big - which is quite possible - I don't understand how this change makes things easier for people to understand template scope. Currently, when control is used in a template, your scope changes to whatever you're controlling. I cant think of any instances where this isn't the case. In the same vein, using with or loop in new SS3 seems to do exactly the same thing - change the scope to whatever you're passing to the template.

I also don't understand what the difference is between the two. As I understand it, <% loop %> is for iterating through a set inside a template, whereas <% with %> is for passing one object to template. But what if you pass a dataobjectset to a <% with %>? Or pass only one dataobject to a <% loop %>? Surely, they will perform the same action, regardless - and therefore having two distinct, separate template tags wouldn't make any difference?

I know I'm probably just missing something silly.

Loving the work otherwise, latest beta looks fab, a real improvement.

Thanks! T


Forum Moderator, 1899 Posts

31 May 2012 at 10:53pm


This is more one for the dev list I'd guess, but my take is the currently the control is ambiguous and if passed a null it still outputs stuff within it... taking this forward to loop and with,,, I'd say that "with" should still still render the content, but loop should not.

This is because loop has nothing to loop on, but with is switching scope to an empty one.

But I'm on the fence with it and will wait until it is final to start using it. Right now I'd just repeat that it is taking something with two meanings and making it clear which one should be being used.