Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Alternative Redirect to First Child use

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

Page: 1 2 3
Go to End
Author Topic: 5543 Views
  • tazzydemon
    Avatar
    Community Member
    114 Posts

    Re: Alternative Redirect to First Child use Link to this post

    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

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Alternative Redirect to First Child use Link to this post

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

    5543 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.