Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Howto display asset folders with a file tree in a page template?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 3065 Views
  • patte
    Avatar
    Community Member
    63 Posts

    Howto display asset folders with a file tree in a page template? Link to this post

    Hi,

    my client wants me to build a page template which displays the content of a asset folder and its subfolders. Can someone please give me a tip how to display the content of a asset folder with some kind of tree?

    Thanks much in advance!

    patte

  • SalvaStripe
    Avatar
    Community Member
    89 Posts
  • patte
    Avatar
    Community Member
    63 Posts

    Re: Howto display asset folders with a file tree in a page template? Link to this post

    Hi SalvaStripe,

    thanks for that hint - i think i AM a lucky boy, using ss2.3.1 ;-)

    The problem is that my client wants to display about six or seven hundred image files.... hm, too much for a simple tree, i think.

    Do you know a way to generate a kind of unordered list of those files, like a sitemap?

    patte

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: Howto display asset folders with a file tree in a page template? Link to this post

    hm i looked into the DB tabel: FILE

    i think all entries there are entries what are in "assets", sooo..

    there are some different "ClassName" like

    Folder
    Image
    File

    ###############################

    when i want to make a page, that returns all my uploaded googleanalytics from the "googleanalyticsfolder" in my assets, i have to look up, what ID this folder has. then i use this code:

    mysite/code/GoogleAnalytics.php
    <?php

    class GoogleAnalytics extends Page {
       static $db = array(
       );
       static $has_one = array(
       );
    }

    class GoogleAnalytics_Controller extends Page_Controller {
       function GoogleAnalyticsList() {
          
          $GoogleAnalyticsList = new DataObjectSet();
          
          $result = DB::query("SELECT * FROM File WHERE ParentID = '293' ORDER BY Name DESC");
          if($result) {
             foreach($result as $value) {
                $eintraege = array(
                               'ID' => $value['ID'],
                               'Name' => $value['Name'],
                               'Title' => $value['Title'],
                               'Filename' => $value['Filename']
                               );
                $GoogleAnalyticsList->push(new ArrayData($eintraege));
             }
          }
          return $GoogleAnalyticsList;
       }
    }

    ?>

    themes/MYTHEME/templates/Layout/GoogleAnalytics.ss

    ...
    ...
    <center>
    <% control GoogleAnalyticsList %>
    <a href="$Filename" target="_blank">$Name</a>
    <% if Last %><% else %><hr /><% end_if %>
    <% end_control %>
    </center>
    ...
    ...
    ###############################

    so, back to problem:

    you can get with that code all "Images" or all files except folders (ClassName != 'Folder'), or you can get at first all Folders with ID, then you can fill between the folders an array with the files, who has ParantID = current Folder ID, after this you can output it nice..

    hm, but just for outputting all Images or all Files, you can use this code i think..

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    +
    + I know, there is a better way with "dataobject::get(..." or stuff like this.. but i did not yet used it.. but soon ;) i promise!
    +
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    i hope you need some stuff from here^^

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: Howto display asset folders with a file tree in a page template? Link to this post

    OKAY here is the better way: (check the syntax please )

    PHP FILE
       function ShowTheStuff() {
          $obj = "File";
          $filter = "ClassName != 'Folder'";
          $sort = "ID ASC";
          $join = "";
          $limit = "";
          
          $records = DataObject::get($obj, $filter, $sort, $join, $limit);
          return $records;
       }

    SS FILE
    <% if ShowTheStuff %>

    <% control ShowTheStuff %>

    <a href="$FileName" target="_blank">$Name</a>

    <% end_control %>

    <% else %>

    Nothing FOUND!

    <% end_if %>

    it is NOT testet, nothing from this here. but this was in my head.. maybe is does work!

  • patte
    Avatar
    Community Member
    63 Posts

    Re: Howto display asset folders with a file tree in a page template? Link to this post

    I will give it a try. Thanks for that & greetings from Cologne!

    3065 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.