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

How do I get the Page Type of the Parent.


Go to End


3 Posts   6041 Views

Avatar
micahsheets

Community Member, 165 Posts

27 November 2008 at 11:20am

I would like to know how to get the Page Type of the Parent of the current page. All my level(2) pages are of the same page type, however the parent pages are of various types. I need to make changes in the child pages based on what the parent page's page type is.

I want to do this in the Class php file not in the template so <% control Parent %> won't work for me.

Avatar
Sam

Administrator, 690 Posts

28 November 2008 at 10:31am

<% control Parent %> just calls $this->Parent() if that method exists, or $this->Parent if the method doesn't.

So, to do what you want, use:

$this->Parent()->ClassName

Avatar
micahsheets

Community Member, 165 Posts

2 December 2008 at 6:36am

Thank you for your answer. I am still trying to get a handle on PHP classes and how inheritance works. I assume that $this is a reference to the current page being displayed. However it seems that if I get the value of $this in the page, it is different than if I get the value in the page_controller. In the case of

$this->Parent()->ClassName
,

do I call it in the page or controller and why?