Jump to:

5451 Posts in 1673 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Modify FileField

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

Page: 1 2 3
Go to End
Author Topic: 2862 Views
  • JuLo
    Avatar
    Community Member
    37 Posts

    Modify FileField Link to this post

    Hi,

    I'd like to modify FileField (or create a new type of field) so it can accept a folder instead of only files.

    (I basically just want to have a browse button and save the path that I pointed to)

    Can anyone point me into the right direction?

    Thanks

    Julien

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Modify FileField Link to this post

    I don't quite understand what you're trying to do.
    Do you want to select a folder on your local computer and store the path to that folder?
    Or do you want to be able to select a folder on the server (from the assets folder)?

  • JuLo
    Avatar
    Community Member
    37 Posts

    Re: Modify FileField Link to this post

    A folder on the server.

    I've created a sort of slideshow in Flash and would like to be able to pass a path to it (through a php) to tell it which folder to get its pictures from.

    Thanks in advance for your help.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Modify FileField Link to this post

    You can just use TreeDropdownField with a DataObjectSet of all the folders. Something like "new TreeDropdownField('Folder', 'Select a Folder', 'Folder')" should do the job.

  • JuLo
    Avatar
    Community Member
    37 Posts

    Re: Modify FileField Link to this post

    Oh OK. That seems simple enough.

    I'll give that a shot.
    Thanks

  • JuLo
    Avatar
    Community Member
    37 Posts

    Re: Modify FileField Link to this post

    Ok.
    I tried it by including this in my pages getCMSfields
          $fields->addFieldToTab("Root.Content.Banner", new TreeDropdownField("FolderForBanner", "Choose a folder to get the images for the slideshow from", "Folder"));

    It seems to work.

    But I don't know how to use the selected path in the .ss Page.
    If I just put $FolderForBanner in the ss file, it obviously cannot work.
    How to turn this "path object" into a string?

    Some more help please?

    Thanks.

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Modify FileField Link to this post

    First get the folder-object in your code .... And feed that to your template :

    $tmpFolder = DataObject::get_by_id("Folder",$FolderForBannerID);
    return $tmpFolder

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Modify FileField Link to this post

    Actually that is completely unnecessary. You can just access a $has_one relationship in your template by using $HasOneName. You then can do $HasOneName.URL or $HasOneName.RelativePath or whatever in your template.

    2862 Views
Page: 1 2 3
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.