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.

General Questions

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

Howto display asset folders with a file tree in a page template?


Reply

6 Posts   3088 Views

Avatar
patte

14 May 2009 at 7:02pm Community Member, 63 Posts

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

Avatar
SalvaStripe

14 May 2009 at 10:25pm Community Member, 89 Posts

you are a lucky boy, when you use ss2.3.1

http://doc.silverstripe.com/doku.php?id=simpletreedropdownfield

Avatar
patte

15 May 2009 at 12:25am Community Member, 63 Posts

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

Avatar
SalvaStripe

15 May 2009 at 1:28am Community Member, 89 Posts

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^^

Avatar
SalvaStripe

15 May 2009 at 1:39am (Last edited: 15 May 2009 1:41am), Community Member, 89 Posts

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

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!

Avatar
patte

15 May 2009 at 1:48am Community Member, 63 Posts

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