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.

Customising the CMS /

Alternative Redirect to First Child use


Go to End
Reply


18 Posts   6114 Views

Avatar
tazzydemon

Community Member, 123 Posts

18 February 2012 at 9:58am

Its easier if you just stick this at the end of your page controller init function rather than use the template

public function init() {
parent::init();

if($this->RedirectToChildOne && $this->Children()->Count()){
Director::redirect($this->Children()->First()->AbsoluteLink());

This feature is invaluable if one is using jquerymobile since otherwise the root page is invisible and its content has to be moved to be its own first child

Avatar
NickJacobs

Community Member, 144 Posts

20 March 2012 at 11:14am

Edited: 20/03/2012 11:15am

Hi, just in case anyone wants a variation...I just test to see if the page has any content, then redirect to the first child if not.

if(!$this->dbObject('Content')->hasValue()){
if($this->Children()->Count()){
Director::redirect($this->Children()->First()->AbsoluteLink());
}
}

Go to Top