Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Control scope

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

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

Page: 1 2 3
Go to End
Author Topic: 6864 Views
  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Control scope Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Control scope Link to this post

    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!

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Control scope Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Control scope Link to this post

    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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Control scope Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Control scope Link to this post

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

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Control scope Link to this post

    LOL. Easy now.....

  • kusi
    Avatar
    Community Member
    21 Posts

    Re: Control scope Link to this post

    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?

    6864 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.