-
- 24,544 Posts
If the page is cached, I think the snippet output for that page might be cached with it.
Is that your complete TV? You don’t have to use the @EVAL binding here;
[!GetDir? &Dir=`assets`!]
will work just fine in a TV.
-
- 24,544 Posts
Quote from: sottwell at Sep 06, 2009, 05:25 AM
Is that your complete TV? You don’t have to use the @EVAL binding here;
[!GetDir? &Dir=`assets`!]
will work just fine in a TV.
I could swear I tried that first and it didn’t work. Hence the awkward @EVAL statement. (Maybe I used a Revo-style tag).
Actually what you need here is a Wayfinder that reads from the filesystem instead of the database. It should be templateable as Wayfinder is, and have a parameter to indicate levels and starting directory, just as Wayfinder does. And one more parameter to indicate filetypes as well, I would think. That shouldn’t be difficult; we could call it Filefinder!
And here it is (in its first version; no templating or multiple folders yet)
<?php
/** Filefinder - create a menu from the filesystem
* Wayfinder for files
* Author - [email protected]
* Created - Sept 2009
* Version 1
*
* @Parameters:
* &directory - the name of the folder the files are in; default ''
* &basedir - the location of the folder; default 'assets/files'
* &fullpath - the full path to the folder; default 'MODX_BASE_PATH + $basedir
* &filetype - file type of files to list for download; default '.pdf'
*
*@Usage
* to list .pdf files in the assets/files directory
* [!Filefinder!]
* to list .pdf files in assets/files/downloads
* [!Filefinder? &directory=`downloads`!]
* to list .doc files in assets/files/docs
* [!Filefinder? &directory=`docs` &filetype=`.doc`!]
* to list .whatever files in the "downloads" directory in the web root
* [!Filefinder? &basedir=`downloads` &filetype=`.whatever`!]
**/
// set up directory path
$directory = isset($directory) ? $directory . '/' : '';
$basedir = isset($basedir) ? $basedir . '/' : 'assets/files' . $directory;
$fullpath = isset($fullpath)? $fullpath .'/' : MODX_BASE_PATH . $basedir;
$fullURL = MODX_BASE_URL . $basedir;
// list eligible files
$filetype = isset($filetype) ? $filetype : '.pdf';
if ($handle = opendir($fullpath)) {
$list = '<ul>';
while (false !== ($file = readdir($handle))) {
if ((strpos($file, '.') != 0) && (strpos($file, $filetype, strlen($file) - strlen($filetype)) !== false)) {
$list .= '<li><a href="' . $fullURL . $file . '">' . $file . '</a></li>';
}
}
closedir($handle);
}
$list .= '</ul>';
return $list;
?>
-
- 2,877 Posts
Awesome
__________________________
| _______________________ |
| | | |
| | Welcome to MODx town! | |
| | Enjoy your stay :) | |
| |_______________________| |
|___________________________|
-
- 24,544 Posts
That’s a really nice snippet, but I don’t see how it will help Sinbad, who wants checkboxes in a TV so the editor can select which files show in the download list.
-
- 884 Posts
I see that it output the files list from the directory but I want to show only selected files not the whole folder content. Bob’s snippet let you check mark the files you want displayed.