Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Generated Menu Items

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

Page: 1
Go to End
Author Topic: 1479 Views
  • Apophenian
    Avatar
    Community Member
    46 Posts

    Generated Menu Items Link to this post

    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

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Generated Menu Items Link to this post

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

    Cross-reference

    Hope this helps,
    Ben

  • ohm
    Avatar
    Community Member
    3 Posts

    Re: Generated Menu Items Link to this post

    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

    1479 Views
Page: 1
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.