Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Linking multiple pages using has_many and TreeMultiselectField

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

Page: 1
Go to End
Author Topic: 965 Views
  • maxx
    Community Member
    4 Posts

    Linking multiple pages using has_many and TreeMultiselectField Link to this post


    On my Homepage (PageType: HomePage) I would like to have a list of Teasers to use. Each Teaser is defined in a separate entry (PageType: HPTeaser) in the Content-Tree. The idea is to use a teaser on several pages, being able to change the content of the teaser in a single place.

    I used the following code in my HomePage.php file:

    class HomePage extends Page {
       public static $db = array(
       public static $has_many = array(
          "HPTeasers" => "HPTeaser"
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $hpteaserfield = new TreeMultiselectField(
             "Homepage Teasers",

          $fields->addFieldToTab("Root.Content.Main", $hpteaserfield);
          return $fields;

    The DropDown is correctly displayed while editing a page of type HomePage, but I have the following problems:

    - The selection is not limited to entries of type HPTeaser
    - When I select one ore more entries they are listed correctly, but nothing seems to be saved to the database (when I reload the editor the field HPTeasers is always empty

    So what could I do to fix these problems? And is there a better FieldType to use (eg. allowing Drag&Drop reordering of the selected Teasers)?

    Many Thanks for your help


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.