We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27330
    • 884 Posts
    thanks guys for the replies.
    don’t know why the modifier won’t work for me.
    the front end output comes out like this:

    <li>assets/files/products/AltronixAltronix-ALTV2416300UL.pdf</li>


    that’s in a Delimited list with <li> seprator.

    anyone knows how to make them clickable?
    I also see that the last / is missing between the last dir and filename.
    sucks I see it on my screen so close to work yet not working smiley
    • the output list should be :


      <li><a href="assets/files/products/AltronixAltronix-ALTV2416300UL.pdf">AltronixAltronix-ALTV2416300UL.pdf</a></li>
        • 27330
        • 884 Posts
        thanks, that part I know smiley
          • 27330
          • 884 Posts
          sorry if I sounded bitchy up there ^,
          what I mean is that I know this is how the output should be. My issue is with @DIRECTORY if there is any settings that will let me have the list as UL of links or am I wasting my time trying to get it to work and should look at something like external snippet that will do it.

          It’s just something I *thought* is pretty common to have and hoped there is an out of the box solution...
            • 3749
            • 24,544 Posts
            I think this does what you want. It works in Evo. A mysterious, base_url is inserted at the beginning of each href. The url prefix is not in the database, as far as I can tell. It’s inserted dynamically when the TV is rendered. I have no idea why. The url prefix is malformed in Revo, so I can’t get it to work there.

            Create a TV called DirList.

            Turn the delimiter output off.

            Use no output widget (leave it blank).


            In the TV’s Input Option Values field, put this:

            @EVAL return($modx->runSnippet('GetDir'));


            Display the TV with this tag:

            [*DirList*]



            Create a GetDir snippet with this code:

            <?php
            
            $dir = 'c:/xampp/htdocs/modx097/assets/';
            $url_base = 'assets/';
            
            
            $output = '';
            $first = true;
            
            if ($handle = opendir($dir)) {
                while (false !== ($file = readdir($handle))) {
                    if ($file != "." && $file != ".."  && (!is_dir($dir . $file)) ) {
                        if (!$first) { 
                            $output .= '||';
                        };
                        $output .= $file. '==' . '<li><a href="' . $url_base . $file . '">' . $file . '</a></li>';
                        if ($first == true) $first = false;
                    }
                }
                closedir($handle);
                return $output;
            }
            ?>


            Set $dir and $url_base appropriately.

            BTW -- If you change the snippet, you have to reload the page containing the TV, edit the TV, and save the page before you’ll see the change.

            I spent most of the day trying to get it to work in Revo before trying it in Evo (sigh).
              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
              my lucky day laugh thanks a lot Bob works a treat on Evo. thanks a 1000000!

              1 thing I noticed, if I have this
              $dir = 'var/www/vhosts/domain.com/httpdocs/assets/files/products/altronix/';
              $url_base = 'assets/';
              

              the url comes out
              http://domain.com/assets/file.pdf


              It drops the full path from the link.
              however if I use the following it works fine.
              $dir = '/var/www/vhosts/domain.com/httpdocs/assets/files/products/altronix/';
              $url_base = 'assets/files/products/altronix/';
              


              How about extending it to snippet that takes parameter such as dir? not to stretch it but if user have lots of dirs it can be extremely useful.


              anyway, thanks again man, you have no idea.
                • 3749
                • 24,544 Posts
                Quote from: sinbad at Aug 31, 2009, 10:15 PM

                $dir = 'var/www/vhosts/domain.com/httpdocs/assets/files/products/altronix/';
                $url_base = 'assets/';
                

                the url comes out
                http://domain.com/assets/file.pdf


                It drops the full path from the link.
                however if I use the following it works fine.
                $dir = '/var/www/vhosts/domain.com/httpdocs/assets/files/products/altronix/';
                $url_base = 'assets/files/products/altronix/';
                

                That’s normal, I’m afraid. MODx automatically adds http://domain.com/ to the beginning of whatever you put in the href and $file is just the filename so you have to prefix it yourself with just the missing part of the path (url_base). I should mention that $dir should always be a file path not a url (e.g. home/usr/public_html/etc.).

                How about extending it to snippet that takes parameter such as dir? not to stretch it but if user have lots of dirs it can be extremely useful.

                It’s easy enough to extend it, but you’re not putting it in a tag, you’re calling it with runSnippet() so you’d have to send the parameters in the runSnippet call:

                @EVAL return($modx->runSnippet('GetDir',array('dir=>','var/www/vhosts/domain.com/httpdocs/assets/files/products/altronix/','url_base'=>'assets/files/products/altronix/')));


                Then in the code, just comment out the $dir and $url_base lines.



                anyway, thanks again man, you have no idea.
                Did I mention that Bob’s Guides now accepts donations? wink
                (At least I hope it does, I’m still waiting for the first one.)
                  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
                  ok but If I had say 20 more directories and I wanted to list all of them, can I do it somehow?

                  ( I don’t care the cluster in the Manager, I can always put that TV in it’s own tab and have all my products subfolders in there.)
                    • 3749
                    • 24,544 Posts
                    To show each one on its own page, I think you’d have to create a new TV for each page, make the changes I mentioned in my last post, and send the appropriate $dir and $url_base in the @EVAL statement.

                    If you wanted to show them all on one page, it would be tricky -- you’d have to do the above and then create a bunch of TVs on the page and use @DOCUMENT with each one (or, I think maybe you could use Ditto).

                    I guess another way would be to create two more TVs -- Dir and BaseUrl, set them for each page, and have the snippet check them to get those variables. Ultimately, that’s probably the way to do it. I could do that easily in Revo. I’m sure it could be done in Evo but I’d have to check to see how.

                    Let me know if they go on separate pages and I’ll see if I can work something out. I’m going to be really busy for the next few weeks so I’m not sure when it would happen.
                      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
                      yes I want to show all the pdf checkboxes on one page . problem is that it’s not modx documents that I can set TVs on but actual product files on the server. ie
                      Products_dir>>
                               Samsung>>
                                  Samsung-001.pdf
                                  Samsung-001.pdf
                               Sony>>
                                  Sony-001.pdf  
                      


                      If I could add the additional paths to the snippet, or ultimately, have the snippet display all files under the Products directory and all sub dirs.