Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Access page details from linked pages in GridField?

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

Page: 1
Go to End
Author Topic: 286 Views
  • suntrop
    Avatar
    Community Member
    131 Posts

    Access page details from linked pages in GridField? Link to this post

    I added a GridField to my pages to store related pages. Currently I just store the link to the related page in the GridField but I'd like to have all details of the related page (content, title, etc.) in my page templates. How do I get access to all that data? Do I have to load them in my page.php or is there a way just within my templates?

    In my template I don't have access to the content and other details of the related page. Only the fields from the GridField.

    <% control RelatedPages %>
             <div>
                <span>$Title</span>
                <span>$Meta.Description</span>
                <p>$Content</p>
             </div>
          <% end_control %>

    function getRelatedPages() {
       return DataObject::get("RelatedPage");
    }

    public function getCMSFields() {
          $fields = parent::getCMSFields();

          $displayColumns = new GridFieldDataColumns();
        $displayColumns->setDisplayFields(array(
             'Relted.MenuTitle' => 'Resort'
        ));

          $gridFieldConfig = GridFieldConfig::create()->addComponents(
             new GridFieldToolbarHeader(),
             new GridFieldAddNewButton('toolbar-header-right'),
             new GridFieldEditButton(),
             new GridFieldDeleteAction(),
             $displayColumns
        );

        $gridField = new GridField("Related", "Pagelist", $this->relatedPages(), $gridFieldConfig);

        $fields->addFieldToTab("Root.Main", $gridField);

          return $fields;
       }

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