Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

Access page details from linked pages in GridField?


Reply

297 Views

Avatar
suntrop

15 April 2013 at 8:22am Community Member, 131 Posts

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