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


Reply

18 Posts   5926 Views

Avatar
tazzydemon

18 February 2012 at 9:58am Community Member, 122 Posts

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

20 March 2012 at 11:14am (Last edited: 20 March 2012 11:15am), Community Member, 144 Posts

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());
}
}