Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Control scope


Go to End


21 Posts   8705 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

15 June 2008 at 12:55pm

Yeah totally a important thing to have access to for sites with rather complicated data relationships. (Well, 3 levels isn't that complicated really!). I know Smarty pumps out a large series of arrays that are accessable anywhere simply by calling $firstLevel['value'], $secondLevel['value'] etc.


I'll keep an eye on the changelogs. If you remember, it'd be cool to post any further developments on this here, as this limitation will be a pretty important factor in choosing SS for complicated client requirements for us. I still don't really understand the context of Ingo's work-around.
Cheers
Aaron

Avatar
Willr

Forum Moderator, 5523 Posts

15 June 2008 at 1:08pm

Edited: 15/06/2008 1:09pm

Ok so your on a Page with fields like $Title, $URLSegment etc so in PHP terms $Page->Title etc. These are fields / methods on the Page Object. Ingos method is adding the Page Object on to the Member Object. So that $Page->Title or $Title on the 'parent level' (the title field on the Page object) can be called within that member control By $ParentScope.Title or you can then add another control inside member to go back up a level

$Title // "Test"
<% control Member %>
$Title // Member doesnt have a Title
$ParentScope.Title // "Test" 
<% end_control %>

As you added the Parent Object (in this case Page) to the member object using customize(). It 'appends' the current Object ($this) to the Member Object to a variable called ParentScope. Which is what you can call to access parent elements.

return $members->customise(array( 
'ParentScope' => $this //  
)); 

Hope thats not too confusing. Even if it doesnt have paragraph breaks!

Avatar
Double-A-Ron

Community Member, 607 Posts

15 June 2008 at 1:13pm

Ah, I think I'm getting it. The thing I was having trouble following is just what "Members" actually was.
I am assuming that the "Members" object in Ingo's example extends the Parent that we are trying to gain access to?

Avatar
Willr

Forum Moderator, 5523 Posts

15 June 2008 at 1:21pm

Members can be any other Object. In this examples Members is just a Member on the Site. But you can append with customize to any other dataobject. Like a latest news feed, or any other Object you are returning

Avatar
Sean

Forum Moderator, 922 Posts

15 June 2008 at 3:37pm

Edited: 15/06/2008 3:39pm

The parent scope can be accessed using $Top, as well. This method doesn't require any additional custom code, as $Top is a built in control.

For example:

$Title
<% control Members %>
   $Top.Title
<% end_control %>

$Top.Title will return the same as $Title outside of the <% control Members %> scope.

Sean

Avatar
Willr

Forum Moderator, 5523 Posts

15 June 2008 at 3:43pm

This was raised like 4 posts ago sean, geez Sean read the whole thread! :P

Avatar
Double-A-Ron

Community Member, 607 Posts

15 June 2008 at 3:45pm

LOL. Easy now.....

Avatar
kusi

Community Member, 21 Posts

13 August 2008 at 4:46am

Great discussion, but it not seems to be the answer of the question, because OK I can use prefix Top and probably I'll get access to something from parent, but how can I manipulate the value for example by parent function with just one or two arguments..it's very important to me because i've been looking for it for 2 hours, changing code and NOTHING it should not very difficult but very useful. could anyone help me cope with it?