Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Creating related pages in SS3

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 223 Views
  • lozhowlett
    Community Member
    146 Posts

    Creating related pages in SS3 Link to this post

    Hi everyone

    Just trying to create a simple related pages, which oddly I can not find a tut for anywhere! I will make one once this is finished.

    What I want to do is pull through the Related Page details into the summary fields, so I can see whats related instead of just the ID. I have no idea how to do this...

    So i have...

    class RelatedPage extends DataObject {

    public static $db = array(
    "SortOrder" => "Int",
    "RelatedPageID" => "Int"

    public static $has_one = array(
    "Page" => "Page"

    public static $has_many = array(

    public static $field_labels = array(

    static $summary_fields = array (

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Main',new TreeDropdownField("RelatedPageID", "Select related page", "SiteTree"));
    return $fields;

    public function Link(){
    if ($this->RelatedPageID){
    $doSet = DataObject::get_by_id("Page", $this->RelatedPageID);
    $parentID = $doSet->ParentID;
    $URLString = $doSet->URLSegment;
    while ($parentID != 0){
    $doSet = DataObject::get_by_id("Page", $parentID);
    $parentID = $doSet->ParentID;
    $URLString = $doSet ->URLSegment . '/' . $URLString;
    return Director::BaseURL() . $URLString;
    } else {
    return false;


    On the summary page of "Page" i would like to see

    Page Title, Thumbnail (which is and has_one image on Page) and Link (which is the function above).

    Any ideas?


  • Bambii7
    Community Member
    254 Posts

    Re: Creating related pages in SS3 Link to this post

    Hi Lozhowlett.

    There might be a better way. But you could easily mimic the Link function to return the summary of the related page. But I think there is an error in the summary_fields at the mo. Try updating the below code, renaming Link to getLink. Then reference 'Link' in the summary field.

    static $summary_fields = array (
    public function getSummary() {
    public function getLink() {

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.