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.

Archive

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

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

Getting data from another page


Go to End
Reply

9 Posts   2997 Views

Avatar
hitautodestruct

16 January 2008 at 4:19am Community Member, 19 Posts

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

16 January 2008 at 4:40am Community Member, 501 Posts

yes, of course:

In your template:

$Parent.Slogan

Or, when you're not in a child:

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

Avatar
hitautodestruct

16 January 2008 at 4:51am Community Member, 19 Posts

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

16 January 2008 at 4:56am Community Member, 501 Posts

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

16 January 2008 at 4:59am Community Member, 19 Posts

Thanks m8.

Wasn't aware you could chain variables like that.

Avatar
dio5

16 January 2008 at 5:00am Community Member, 501 Posts

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

Avatar
hitautodestruct

17 January 2008 at 9:25pm Community Member, 19 Posts

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

17 January 2008 at 9:30pm Community Member, 501 Posts

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