Jump to:

23545 Posts in 19310 Topics by 2888 members

General Questions

SilverStripe Forums » General Questions » SS3: with/loop vs. control

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

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

Page: 1
Go to End
Author Topic: 879 Views
  • TheHacksaw
    Community Member
    2 Posts

    SS3: with/loop vs. control Link to this post

    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

  • swaiba
    Forum Moderator
    1796 Posts

    Re: SS3: with/loop vs. control Link to this post


    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.

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.