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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

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


Go to End


6 Posts   4898 Views

Avatar
patte

Community Member, 63 Posts

14 May 2009 at 7:02pm

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

Community Member, 89 Posts

14 May 2009 at 10:25pm

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

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

Avatar
patte

Community Member, 63 Posts

15 May 2009 at 12:25am

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

Community Member, 89 Posts

15 May 2009 at 1:28am

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

Community Member, 89 Posts

15 May 2009 at 1:39am

Edited: 15/05/2009 1:41am

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

Community Member, 63 Posts

15 May 2009 at 1:48am

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