I have the variable $GiftID in my page.
I want to cycle through all of my gift objects using my function getGifts().
When the $ID of the gift is equal to the $GiftID of the page then I want something to happen.
<% control getGifts %>
<% if CurrentPage.GiftID = ID %>This is it!<% end_if %>
<% end_control %>
I can't figure out how to access the variables from outside of the control within the if statement... Am I missing something very simple? I feel there should be an easy way to do this.
I realize this is a late reply, sorry for that. You can use $Top to access Page variables from within a control/loop/with structure. However using
<% if Top.GiftID = ID %>This is it!<% end_if %>
would check on the litteral value 'ID', and not on the value of the variable $ID. I know in SilverStripe 3 you should be able to use the following:
<% if Top.GiftID = $ID %>This is it!<% end_if %>
But I don't think this is possible in 2.x. In that case you could maybe (re)build the function getGifts() so that an extra property $ValidID (true/false) is returned for every gift object. Or some other php logic...