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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

TreeDropdownField not displaying anything on SilverStripe 3.0


Go to End


2 Posts   2225 Views

Avatar
mrsteveheyes

Community Member, 15 Posts

13 July 2012 at 9:35pm

Hi there.

I am wanting to do related pages on my site. How I did this on 2.4 was use a related SiteTree object and TreeDropdownField. The code I'm using is bellow:

 public static $has_one = array(

        'Feature1Page'         => 'SiteTree',
    );

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

        $fields->addFieldToTab('Root.Main', new TreeDropdownField('Feature1PageID', 'Feature 1 Link', 'SiteTree'));

        $return $fields;
     }

The dropdown menu shows in the CMS, but when I go to select something and press the arrow down button nothing is shown. Am I missing something or done something wrong? Or is this a bug that needs fixing in 3.0?

Cheers,
Steve

Avatar
vegetav

Community Member, 23 Posts

7 August 2012 at 11:42pm

That looks like it should work to me. I am doing using the TreeDropdownField in a DatObject in 3.0.1 in the same way thaty ou are and it works fine for me.

Here is my code for reference...

class Feature extends DataObject {
	static $db = array (
		'Title' => 'Text',
	);
    
	static $has_one = array (
        'HomePage' => 'HomePage',
        'LinkPage' => 'SiteTree',
	);

    public static $summary_fields = array(
        'Title' => 'Title',
    ); 
    
    public function getCMSFields() {
        return new FieldList(
            new TextField('Title'),
            new TreeDropdownField('LinkPageID', 'Link', 'SiteTree')
        );
    }
}

And in my template...

<% loop Features %>
	<a href="$LinkPage.Link" id="link$ID">$Title</a>
<% end_loop %>