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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

[SOLVED] Retrieving page links from DOM simpletreedropdown

Go to End

2 Posts   1368 Views


Community Member, 49 Posts

6 September 2011 at 11:53pm

Edited: 07/09/2011 1:35am

For the life of me i cant get this to work.. what im wanting to do is attach a page link to a "Read More" anchor. The simpletreedropdown shows in DOM Just fine, but i just cant get the link to show from the database. The PageLinkID is in the database and also the ID of the page that i want to link to gets populated into the PageLinkID column

This is what i have in my class file:


class ImageResource extends DataObject
    static $db = array (
        'Title' => 'Text',
        'Caption' => 'Text'
    static $has_one = array (
        'HomePage' => 'HomePage',
        'Attachment' => 'Image', //Needs to be an image
        'PageLink' => 'SiteTree'
    public function getCMSFields_forPopup()
        return new FieldSet(
            new TextField('Title'),
            new TextareaField('Caption'),
            new FileIFrameField('Attachment'),
            new SimpleTreeDropdownField( 'PageLinkID', 'Link To Page', 'SiteTree' )  

Heres HomePage.php

 * Defining the HomePage page type

class HomePage extends Page {
   static $db = array(
     'effect' => "Enum('sliceDown,sliceDownLeft,sliceUp,sliceUpLeft,sliceUpDown,sliceUpDownLeft,fold,fade,random','random')",
        'slices' => 'Int(15)',
        'animSpeed' => 'Int(500)',
        'pauseTime' => 'Int(3000)',
        'startSlide' => 'Int()',
        'directionNav'  => "Boolean",
        'directionNavHide' => "Boolean",
        'controlNav' => "Boolean",
        'controlNavThumbs' => "Boolean",
        'keyboardNav' => "Boolean",
        'pauseOnHover' => "Boolean",
        'manualAdvance' => "Boolean",
        'captionOpacity' => 'Decimal(2,1,0.8)'

   static $has_one = array(
   static $has_many = array (
        'Images' => 'ImageResource',
        'Panels' => 'NivoSliderPanel',
   // static $allowed_children = array('MainBannersResource');
   function getCMSFields() {
      $fields = parent::getCMSFields();
      $manager = new ImageDataObjectManager(
            $this, // Controller
            'Images', // Source name
            'ImageResource', // Source class
            'Attachment', // File name on DataObject
                'Title' => 'Title', 
                'Caption' => 'Caption',
            ), // Headings 
            'getCMSFields_forPopup' // Detail fields
            // Filter clause
            // Sort clause
            // Join clause
      if (class_exists('DataObjectManager'))$a='DataObjectManager'; else $a='ComplexTableField'; 
      $fields->addFieldToTab("Root.Content.Panels", new $a($this,'Panels','NivoSliderPanel',array('Thumbnail' => _t('Image.PLURALNAME'),'Title' => _t('SiteTree.METATITLE'),'Tagline' => _t('SiteTree.METADESC')), 'getCMSFields_forPopup'));
      $fields->addFieldToTab('Root.SliderSettings', new CompositeField(
               new LiteralField("wrapper","<div style='margin-left: 50px;'>"),
                new HeaderField("settings","Slider Settings"),
                new DropdownField('effect',"Effect", singleton('HomePage')->dbObject('effect')->enumValues()),
                new TextField('slices','Number of slices'),
                new TextField('animSpeed','Animation Speed'),
                new TextField('pauseTime','Display panel time'),
                new CheckboxField('randomStartSlide', 'Random 1st panel?'),
                new CheckboxField('directionNav','Show directional Nav?'),
                new CheckboxField('directionNavHide','Only show on hover?'),
                new CheckboxField('controlNav','1,2,3...'),
                new CheckboxField('controlNavThumbs','Thumbs??'),
                new CheckboxField('keyboardNav','Enable keyboard navigation?'),
                new CheckboxField('pauseOnHover','Stop animation while hovering?'),
                new CheckboxField('manualAdvance','Force manual transitions?'),
                new TextField('captionOpacity','Universal caption opacity 0-1'),
            new LiteralField("wrapper_close","</div>")
      $fields->removeFieldFromTab('Root.Content.Main', 'Content');
        $fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent'); 

   return $fields;

class HomePage_Controller extends Page_Controller { 
       function init(){
        if (Director::isDev()) {
        isset($this->effect) && $this->effect ? $a[]="effect:'{$this->effect}'":null;
        isset($this->slices) && $this->slices ? $a[]="slices:'{$this->slices}'":null;
        isset($this->animSpeed) && $this->animSpeed ? $a[]="animSpeed:'{$this->animSpeed}'":null;
        isset($this->pauseTime) && $this->pauseTime ? $a[]="pauseTime:'{$this->pauseTime}'":null;
        isset($this->startSlide) && $this->startSlide ? $a[]="startSlide:'{$this->startSlide}'":null;
        //TODO: Test how clever is a javascript boolean
        isset($this->startSlide) && $this->startSlide ? $a[]="startSlide:true":$a[]="startSlide:false";
        isset($this->directionNav) && $this->directionNav ? $a[]="directionNav:true":$a[]="directionNav:false";
        isset($this->directionNavHide) && $this->directionNavHide ? $a[]="directionNavHide:true":$a[]="directionNavHide:false";
        isset($this->controlNav) && $this->controlNav ? $a[]="controlNav:true":$a[]="controlNav:false";
        isset($this->controlNavThumbs) && $this->controlNavThumbs ? $a[]="controlNavThumbs:true":$a[]="controlNavThumbs:false";
        isset($this->keyboardNav) && $this->keyboardNav ? $a[]="keyboardNav:true":$a[]="keyboardNav:false";
        isset($this->pauseOnHover) && $this->pauseOnHover ? $a[]="pauseOnHover:true":$a[]="pauseOnHover:false";
        isset($this->manualAdvance) && $this->manualAdvance ? $a[]="manualAdvance:true":$a[]="manualAdvance:false";
        //isset($this->captionOpacity) && $this->captionOpacity ? $a[]="captionOpacity:'{$this->captionOpacity}'":null;
        $a=implode(", ",$a);
            jQuery(window).load(function($) {
    public function forTemplate(){


Finally heres the line in that calls the link:

 <p>$Caption.LimitCharacters(175)<span><a href="$PageLinkID.LINK">Read More</a></span></p>

The line calling the link should have read:

<p>$Caption.LimitCharacters(175)<span><a href="$PageLink.LINK">Read More</a></span></p>


Community Member, 5 Posts

7 September 2011 at 7:08pm

Thanks man! Was just working on the some sort of thing and ran into the same problem. Sure I tried it before but forgot to flush -doh-