22997 Posts in 11853 Topics by 2828 members
Page: 1 2
|Go to End||Next >|
23 February 2009 at 8:52pm
Is there a global variable that I can check which will notify me if I am in a control loop so that I can modify IDs in the code behind (php files) as I would like to append the control's position (ie 1,2,3,....) to the end of the attribute.
For exampe if I have a calendar called FromDate and this is in to be displayed in a control loop, the ID should rather be FormName_FromDate1, FormName_FromDate2, etc, etc
23 February 2009 at 9:56pm Last edited: 23 February 2009 9:57pm
what you're looking for is $Pos (see http://doc.silverstripe.org/doku.php?id=built-in-page-controls#dataobjectset_options)
anyway, i don't know what you're after exactly, but this reads as though it could also be accomplished using a class instead of multiple ids, then doing something like this (jquery):
(you may also use the jquery 'nth-child' selector, but it's much slower)
23 February 2009 at 10:14pm
Thanks - yes I have seen this before. This could work to a point but is there no way to rather do it in the actual PHP class by using a variable such as $Pos rather than in the template or will this also work in the code behinds?
28 February 2009 at 3:27am
sorry for delay
can't exaclty imagine what this might be good for...
could you post some example code?
28 February 2009 at 3:40am
In a PHP class you can use iteratorPos on the object being looped through.
class MyObject extends DataObject
28 February 2009 at 4:27am
Sorry, this does not return anything in a Page_Controller function.
Reason I need this is to make iteration unique since they are not.
28 February 2009 at 4:46am
Please post all of your relevant code.
28 February 2009 at 5:07am
Basically I have a function called MyFunc and in the template I want to be able to make a calendar unique on a form which is in a control. If a click the calendar or use some AJAX thingy it will not work. So this is what the code is:
<% control Event %>
<% end_control %>
PS: I just posted an update to Sapphire on Trac. Hopefully the fix I just submitted will allow for this to work since I can't see any other way for it to work. My fix allows a dynamic parameter to be passed into a function via the template. So, you can have: $Top.CalendarForm($ID)
Page: 1 2
|Go to Top||Next >|