You mean, you put the above pseudo code in the Page class instead of the HTML like I did?
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.
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries
You mean, you put the above pseudo code in the Page class instead of the HTML like I did?
Yes, in a page class.
Ben
Thank you SilverRay! That's a nice idea.
Hey Ben,
Just coincidentally I stumbled on this thread again and noticed that I never followed up, so here it goes, just in case other users find it:
class Page_Controller extends ContentController {
public function init() {
if($this->RedirectToChildOne) {
if($children = $this->Children()) {
if($firstChild = $children->First()) {
Director::redirect($firstChild->Link());
}
}
}
parent::init();
}
}
In this way you can forego the template code. Thanks Ben for reminding me on this method ;)
SR
Let me suggest an improvement: Override the Link method of your class with a code like this:
function Link() {
if($this->RedirectToChildOne) {
if($this->Children()->First())
return $this->Children()->First()->Link();
}
return parent::Link();
}
That way, the page-link will point to the first child if RedirectToChildOne is checked, saving the user (and the webserver) from a lot of redirects.
For first-child redirects, I usually use a specialized page class (http://pastie.org/803850). I don't see the point in having a checkbox, since you could just as well change the page-type in the Behavior tab. This is preferable imho, since it updates the CMS UI accordingly. You no longer have a content field to enter content that will never be shown and you can use another page-icon that helps the user to easily spot these redirector pages.
Ah, very smart banal, thanks for your suggestion! There can be a lot of redirects indeed when multiple pages in a hierarchy have redirects.
I used to have a separate class for redirects actually, then I thought to bring it to the Page class for universal use, but your approach makes sense. In my case, sometimes a user wants to revert back to the original page without a redirect, that's why I made it a checkbox, the original page with contents is then still there...
Anyway, I should think more of overriding existing methods ;)
SR
@banal: Many thanks for sharing, that was exactly what I was looking for :-) Saved me a lot if time!
Best Bjoern
Nice banal, very nice.
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries