We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27330
    • 884 Posts
    I hopped for cache solution smiley
    but doesn’t this already called cache?
    I mean how do you pass cache/uncached with $modx->runSnippet?
    @EVAL return($modx->runSnippet('GetDir',array('Dir'=>'assets/')));
      • 3749
      • 24,544 Posts
      If the page is cached, I think the snippet output for that page might be cached with it.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        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.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 3749
          • 24,544 Posts
          Quote from: sottwell at Sep 06, 2009, 12: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). embarrassed
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            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;
            ?>

              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 16183
              • 1,390 Posts
              @Susan,

              This is brilliant! Thx for sharing. smiley

              cheers/k
                • 20413
                • 2,877 Posts
                Awesome
                  __________________________
                |  _______________________  |
                | |                       | |
                | | Welcome to MODx town! | |
                | | Enjoy your stay  :)   | |
                | |_______________________| |
                |___________________________|
                
                  @hawproductions | http://mrhaw.com/

                  Infograph: MODX Advanced Install in 7 steps:
                  http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                  Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                  http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                  • 3749
                  • 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.

                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 27330
                    • 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.
                      • 27330
                      • 884 Posts
                      opps 8:26
                      hi good thinking wink