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

Getting data from another page


Go to End


9 Posts   4410 Views

Avatar
hitautodestruct

Community Member, 19 Posts

16 January 2008 at 4:19am

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?

Avatar
dio5

Community Member, 501 Posts

16 January 2008 at 4:40am

yes, of course:

In your template:

$Parent.Slogan

Or, when you're not in a child:

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

Avatar
hitautodestruct

Community Member, 19 Posts

16 January 2008 at 4:51am

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.

Avatar
dio5

Community Member, 501 Posts

16 January 2008 at 4:56am

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)

Avatar
hitautodestruct

Community Member, 19 Posts

16 January 2008 at 4:59am

Thanks m8.

Wasn't aware you could chain variables like that.

Avatar
dio5

Community Member, 501 Posts

16 January 2008 at 5:00am

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

Avatar
hitautodestruct

Community Member, 19 Posts

17 January 2008 at 9:25pm

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.

Avatar
dio5

Community Member, 501 Posts

17 January 2008 at 9:30pm

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 :)

Go to Top