Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Read folder

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

Page: 1
Go to End
Author Topic: 299 Views
  • silverprogramer
    Avatar
    Community Member
    1 Post

    Read folder Link to this post

    HI im starting with Silverstripe, some one can help me?

    Hi im trying to read some directory to do my carousel

    my problem here is: how can i access from my values on a loop

    Template:

    <% loop getSliderFiles %>

    #HOW I CAN READ THE NAME OF MY FILES FROM HERE?

    <% end_loop %>

    Controller php:

    public function getSliderFiles()
    {
    $list = new ArrayList();
    foreach (scandir(Director::baseFolder().'/assets/slider/' ) as $file_die)
    {
    $list->push($file_die);
    }

    return $list;
    }

    any help?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Read folder Link to this post

    It's quite simple.

    public function getSliderFiles() {
       $folder = Folder::find_or_make('slider');
       return $folder->Children();
    }

    <% loop getSliderFiles %>
    $Filename
    <% end_loop %>

    ---
    Edit: Or if you're fancy, you can define the folder as a has_one relation to the DataObject. e.g.:

    class Page extends SiteTree{
       private $has_one = array(
          'Slider' => 'Folder'
       );
    }

    <% if SliderID %>
    <% loop Slider.Children %>
    $Filename
    <% end_loop %>
    <% end_if %>

    299 Views
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.