Skip to content

Instantly share code, notes, and snippets.

@muskie9
Last active August 29, 2015 14:04
Show Gist options
  • Save muskie9/e765bc4b94c4d3e11b4d to your computer and use it in GitHub Desktop.
Save muskie9/e765bc4b94c4d3e11b4d to your computer and use it in GitHub Desktop.
PageLink dropdown relation for linking in Layout
<?php
class HomePage extends Page {
private static $has_one = array(
'PageLink' => 'SiteTree'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new TreeDropdownField("PageLinkID", "Page to link to", "SiteTree"), 'Content');
$this->extend('updateCMSFields', $fields);
return $fields;
}
}
@muskie9
Copy link
Author

muskie9 commented Jul 23, 2014

You would then use <a href="$PageLink.Link">$PageLink.Title</a> in the Layout of that page type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment