21475 Posts in 5781 Topics by 2620 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 769 Views |
-
page attributes/methods from inside a control

21 June 2011 at 11:34am Last edited: 21 June 2011 11:36am
if I have a function in the Page_Controller
public function getMemberType() {
$family_member = $this->getFamilyMember();
return $family_member->MemberType()->Name;
}why does this work
<% if getMemberType = Pathfinder %>
and this also works
<p>$CurrentPage.getMemberType</p>
but this does not
<% if CurrentPage.getMemberType = Pathfinder %>
at this point I'm inside a contol of some other object but I want to reach back up to the CurrentPage and get the "getMemberType" method.
Help!
-
Re: page attributes/methods from inside a control

21 June 2011 at 11:49am
try
<% if Top.getMemberType = Pathfinder %>
-
Re: page attributes/methods from inside a control

21 June 2011 at 11:52am Last edited: 21 June 2011 11:53am
I get a php parse error ... same as if I use "CurrentPage" instead of "Top" ...
Thanks though
-
Re: page attributes/methods from inside a control

21 June 2011 at 12:13pm Last edited: 21 June 2011 12:24pm
well "Top" is the way to do it, not CurrentPage (http://doc.silverstripe.org/sapphire/en/reference/built-in-page-controls) and without seeing the parse error it's hard to help...
how about
<% control Top %>
<% if getMemberType = Pathfinder %>
stuff
<% end_if %>
<% end_control %> -
Re: page attributes/methods from inside a control

21 June 2011 at 1:24pm Last edited: 21 June 2011 2:13pm
your code works but that is not the problem. I'm not talking about a control loop. If "getMemberType" is a method of the Page_Controller, why does
<% if getMemberType = Pathfinder %>
work but
<% if Top.getMemberType = Pathfinder %>
does not. However
<p>$Top.getMemberType</p>
works just fine. The reason I'm trying to "if Top.getMemberType" is that I'm in a control loop of an object and the Page is no longer accessible to me.
So maybe the question I need answered is "how do I set a variable on a page and access if from anywhere ... even several control loops deep".
BTW, the parse error reported by Apache is "PHP Parse error: syntax error, unexpected '}' in" ...
Thanks!
-
Re: page attributes/methods from inside a control

21 June 2011 at 8:16pm
Just to let you know control is *both* a scope changing operation and loop iterator. So using (in the way I advised) changes the current scope to the "top" context of the page.
I believe they are moving in a less confusing direction for SS3 on this issue.
And I could guess the start of the error! the line number and file and then the contents of the file at that line number would be of benefit - it is possible to debug these "compiled" ss files as they are just php and they do make sense once you go to the line number - the smaller the file the easier it is - best of luck!
-
Re: page attributes/methods from inside a control

22 June 2011 at 5:35pm
I believe they are moving in a less confusing direction for SS3 on this issue.
You're correct. SS3 is separating it out to <% with %> and <% loop %>, but thats not until 3.0.
Perhaps try
<% control Top %>
<% if getMemberType = Pathfinder %>
..
| 769 Views | ||
|
Page:
1
|
Go to Top |



