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.

Customising the CMS

Modify FileField


19 Posts   3075 Views


9 December 2009 at 12:31am Community Member, 37 Posts

@Fuzzio, thanks anyway.

Thanks a lot.
That's what I was looking for.

I have to say that it's not the first I struggle with that kind of stuff in the Silverstripe documentation.
How did you know that the content of TreeDropdownField field can be displayed as URL or as Relative path?
What are the other options?
Where do you find that kind of info?

I seem to only get it from reading posts on the forum of users who have already used it before (e.g. that's how I found out about $Locale.Nice)
(Probably very weird question I know)



9 December 2009 at 12:31am (Last edited: 9 December 2009 12:31am), Community Member, 787 Posts

@AJShort : Well yeah , but we are not sure he is using a has_one ... Many times I've used a dropdown to store a link to the filesystem or the sitetree without having a relationship ....


9 December 2009 at 12:36am Community Member, 37 Posts

Yep. I am using a has_one


9 December 2009 at 12:38am Community Member, 787 Posts


Haha , your previous posting beat me to it...

Good to see it's sorted ! ... ;) Good luck with your project !


9 December 2009 at 12:44am Community Member, 37 Posts

Thanks Fuzzio.

But that just showed me that I must have done something else wrong, because my TreeDropdownField does not seem to save its content.

$FolderForBanner.URL always shows http://localhost/SilverStripe/assets/, no matter what folder I have chosen.

And in the CMS, when I change it, Save And Publish, and refresh the page, the drop down is back to "(Choose)", which I guess means that it did not save the value.

Any ideas.


9 December 2009 at 12:47am Community Member, 787 Posts

Just a quick guess : if you are using a has_one , you should probably safe to FolderForBannerID instead of FolderForBanner ...

Please post your code...


9 December 2009 at 12:55am Community Member, 37 Posts

OK. I have no idea what that means (what ID? Where do I get it from?), so I am posting the code. (unnecessary bits removed)

in Homepage.php
static $has_one = array(
'FolderForBanner' => 'Folder'

public function getCMSFields(){

      $fields = parent::getCMSFields();
      $fields->addFieldToTab("Root.Content.Banner", new TreeDropdownField("FolderForBanner", "Choose a folder to get the images for the slideshow from", "Folder"));
      return $fields;

In the

And as I said earlier, it only returns "http://localhost/SilverStripe/assets/", which suggests that it does not save the value.


9 December 2009 at 1:17am Community Member, 787 Posts

Try :
$fields->addFieldToTab("Root.Content.Banner", new TreeDropdownField("FolderForBannerID", "Choose a folder to get the images for the slideshow from", "Folder"));