Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Getting data from another page

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

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

Page: 1 2
Go to End
Author Topic: 2943 Views
  • hitautodestruct
    Avatar
    Community Member
    19 Posts

    Getting data from another page Link to this post

    Hello.
    I think this should be a real simple one but for some reason I can't seam to manage it.
    I have a slogan that runs through all my site.
    Currently I have a custom "Slogan" field in the CMS for every page type. And I retype the slogan into there for every page.
    What I want to do is to get the "Slogan" field from the top most parent HomePage page type.
    I might have two HomePage page types fathering different children with different slogans and so I would like the page that is asking for the slogan to pick it up from it's first parent HomePage page type.

    Is there any way this could be done?

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Getting data from another page Link to this post

    yes, of course:

    In your template:

    $Parent.Slogan

    Or, when you're not in a child:

    <% control Page(home) %>$Slogan<% end_control %>

  • hitautodestruct
    Avatar
    Community Member
    19 Posts

    Re: Getting data from another page Link to this post

    Brilliant!
    I knew there was an almost blindingly simple way to do this.
    Thanks.

    But say I want the template to grab the "Slogan" from it's topmost parent.
    Just using $Parent.Slogan will only go one level up.
    How would I get to the root HomePage dynamically without giving it a hardcoded name using the:

    <% control Page(home) %>$Slogan<% end_control %>

    Cheers for the quick reply.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Getting data from another page Link to this post

    You can't change the name of the homepage anyway, so you'll always have to call it 'home'.

    But I figure something like $Parent.Parent.Slogan could work, but I'm not sure, havent tried it.

    (do not forget to flush everytime you change yr template... otherwise you might not see the changes)

  • hitautodestruct
    Avatar
    Community Member
    19 Posts

    Re: Getting data from another page Link to this post

    Thanks m8.

    Wasn't aware you could chain variables like that.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Getting data from another page Link to this post

    It's just a guess... I haven't tried it so it might fail

  • hitautodestruct
    Avatar
    Community Member
    19 Posts

    Re: Getting data from another page Link to this post

    Hey,

    I just wanted to let you know that I figured out a way to get to the root and suck out my slogan.
    All I have to use is:

    <% control Level(1) %>
    $Slogan
    <% end_control %>

    It was that simple.
    Thanks for all your post comments you helped me a lot.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Getting data from another page Link to this post

    Yes,

    you might be interested in this page:

    http://doc.silverstripe.com/doku.php?id=built-in-page-controls

    If you haven't already found it by now

    2943 Views
Page: 1 2
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.