Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

1598 Posts in 399 Topics by 403 members

Template Questions

SilverStripe Forums » Template Questions » Generated Menu Items

Page: 1
Go to End
Author Topic: Generated Menu Items 485 Views
  • Apophenian
    avatar
    Community Member
    44 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

    485 Views
Page: 1
Go to Top

Currently Online: mattclegg, sicp

Welcome to our latest member: fearofbuttons

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

Comments on this website? Please give feedback.