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   1609 Views

Avatar
Apophenian

Community Member, 46 Posts

28 May 2009 at 2:01pm

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

Community Member, 181 Posts

29 May 2009 at 12:58am

Edited: 29/05/2009 12:59am

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

Community Member, 3 Posts

27 October 2009 at 5:39am

Edited: 27/10/2009 5:41am

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