18591 Posts in 4875 Topics by 2285 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 2123 Views |
-
Howto display asset folders with a file tree in a page template?

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
-
Re: Howto display asset folders with a file tree in a page template?

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
-
Re: Howto display asset folders with a file tree in a page template?

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
-
Re: Howto display asset folders with a file tree in a page template?

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
<?phpclass 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^^
-
Re: Howto display asset folders with a file tree in a page template?

15 May 2009 at 1:39am Last edited: 15 May 2009 1:41am
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!
-
Re: Howto display asset folders with a file tree in a page template?

15 May 2009 at 1:48am
I will give it a try. Thanks for that & greetings from Cologne!
| 2123 Views | ||
|
Page:
1
|
Go to Top |

