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.

Template Questions

Generated Menu Items


Reply

3 Posts   1574 Views

Avatar
Apophenian

28 May 2009 at 2:01pm Community Member, 46 Posts

I want to be able to have generated menu items displayed as children of a custom page type.

These menu items wouldn't be actual children, but would point to methods in my page_controller. Is there a 'standard' or best way to do this? The easiest way I think would be to have a custom 'MenuChildren' method in my page class and refer to that in the navigation template - is there a better way?

Cheers,

Rane

Avatar
Ben Gribaudo

29 May 2009 at 12:58am (Last edited: 29 May 2009 12:59am), Community Member, 181 Posts

Hello,

Do you mean that you want a given page type to have "fake" children? I've played a little with this: enough to prove the concept but not enough to go live with it.

public function Children() {
$children = new DataObjectSet();
foreach ($this->Children as $childTitle => $childLink) {
$page = new Page();
$page->Title = //$childTitle;
// unsure how to set child page's URL/link
$children->push($page);
}
return $children;
}

[url=http://www.silverstripe.org/general-questions/show/260915]Cross-reference[/url]

Hope this helps,
Ben

Avatar
ohm

27 October 2009 at 5:39am (Last edited: 27 October 2009 5:41am), Community Member, 3 Posts

For my purposes the easiest solution was to override Children, and start by invoking super::Children() and then modify the dataset, like this:

public function Children(){

$children = parent::Children();

if($children) {
foreach($children as $child) {
if ($child instanceof TemaArtikler){

$child->Overskrift = DataObject::get_one("StatiskTekst")->ArtiklerOverskrift;
$child->MenuTitle = $child->Overskrift;
$child->Beskrivelse = DataObject::get_one("StatiskTekst")->ArtiklerTekst;
}

}
}
return $children;
}
}

The above code replaces the title of all "TemaArtikler" pagetypes with userspecified text from a static object.

Hope this helps.

edit: added code tags