Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Link Page with multiple pages with GridField

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

Page: 1
Go to End
Author Topic: 319 Views
  • Allexx
    Avatar
    Community Member
    2 Posts

    Link Page with multiple pages with GridField Link to this post

    Hello,
    I want to add a form where the user in the backend can link a page with multiple other pages. Something like "You might also be interested in..." but NOT dynamically generated.
    I found this tutorial:
    http://blog.fraser-hart.co.uk/silverstripe-3-gridfield-with-many_many-relationship/
    but the problem is, that when I set a relation the site tree is modified.
    What I want is something like:
    Frontpage is linked with About page
    Contact page is linked with About Page and Imprint
    etc.

    How do I have to modify this code to achieve this?

    public static $has_many = array(
        'Boxes' => 'Page'
        );

       public function getCMSFields() {
        $fields = parent::getCMSFields();
        $gridFieldConfig = GridFieldConfig_RelationEditor::create()->addComponents(
             new GridFieldDeleteAction('unlinkrelation')
          );
       
        $gridField = new GridField("Boxes", "Boxes", $this->Boxes(), $gridFieldConfig);
        $fields->addFieldToTab("Root.Boxes", $gridField);
        return $fields;
       }

  • Allexx
    Avatar
    Community Member
    2 Posts

    Re: Link Page with multiple pages with GridField Link to this post

    With help of this post http://www.silverstripe.org/general-questions/show/21867 I'm able to select multiple posts, but the values are not saved and I cannot access them from my template.
    How can I save my selection in the database and access them from my template?

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Link Page with multiple pages with GridField Link to this post

    I suspect you're trying to assign a $has_many with a corrsponding $has_one relation. Also realitistally what you probably want is for Page to have $many_$many $belong_many_many relation with itself since any page can actually belong to multiple other pages http://doc.silverstripe.org/framework/en/topics/datamodel#many-many

    319 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.