17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 2569 Views |
-
Getting data from another page

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?
-
Re: Getting data from another page

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 %>
-
Re: Getting data from another page

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.
-
Re: Getting data from another page

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)
-
Re: Getting data from another page

16 January 2008 at 4:59am
Thanks m8.
Wasn't aware you could chain variables like that.
-
Re: Getting data from another page

16 January 2008 at 5:00am
It's just a guess... I haven't tried it so it might fail
-
Re: Getting data from another page

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. -
Re: Getting data from another page

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
| 2569 Views | ||
| Go to Top | Next > |


