3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 332 Views |
-
How to access a page variables within an if statement within a control?

24 August 2012 at 2:48pm
I have the follow code in my page.
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.$GiftID
<% 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 am using SS 2.9
Thanks!
-
Re: How to access a page variables within an if statement within a control?

2 September 2012 at 2:23am
Hi machiaveli
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...
| 332 Views | ||
|
Page:
1
|
Go to Top |

