We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Ok. My original idea of using extra TVs doesn’t work anyway. The snippet has no way of knowing what the doc ID is (that I know of) since $modx->documentIdendtifier isn’t set when the doc is being edited. Without the doc ID, there’s no way of getting the value of the Dir or UrlBase TVs for that document.

    I tried a bunch of things but nothing worked. :’(

    How important are the checkboxes? Would it be ok to just show all the .pdf files in every directory under products? That would be doable with just a snippet. If not, I can’t see any way of doing what you want without creating a snippet that generates a custom form with the checkboxes in the front end saving its results to a file or DB table for use by another snippet that would display the .pdf file links. That would be some serious programming. wink

      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
    • You should be able to get the ID of the document being edited from the GET array.
        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
        I should have thought of that. $_GET[’id’] has it.

        If Sinbad wants to show different directories on the same page with the editor selecting the files to show with checkboxes, though, it’s still pretty hairy.

        I don’t see any way to do it without a different TV for each dir and hard-coding the Dir and UrlBase into the @EVAL for each TV. I imagine new directories are being added all the time so it could get pretty ugly.
          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
        • I should think that a snippet could build up drop-down select options or check boxes from a scandir or some such thing; loop through the items returned by the scandir and if it’s a directory recurse.
            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 01, 2009, 07:09 AM

            I should think that a snippet could build up drop-down select options or check boxes from a scandir or some such thing; loop through the items returned by the scandir and if it’s a directory recurse.
            Sure, but then you’d have to store the results for use with the display snippet and you’d have to repopulate the checkboxes from the stored data every time you re-visited the page. Doable, but far from trivial. I have something that actually works with TVs. See next message.
              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
              • 3749
              • 24,544 Posts
              Ok, new version. It’s not as bad as I thought. I think this will do exactly what you want.

              Create a TV for each directory you want to show (use duplicate). Use the name of the directory for the Name and the Caption of the TV (I’m not sure if you can use backslashes or not).

              Put this in the Input Option Values (correcting the Dir for each one). Needs a trailing backslash but no leading backslash):

              Assets TV
              @EVAL return($modx->runSnippet('GetDir',array('Dir'=>'assets/')));


              Assets-Snippets TV
              @EVAL return($modx->runSnippet('GetDir',array('Dir'=>'assets/snippets/')));


              Here’s the new GetDir snippet:

              <?php
              $output = '';
              $first = true;
              
              $base = $modx->config['base_url'];
              
              $url_base = $base . $Dir;
              $dir = $modx->config['base_path'] . $Dir;
              
              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;
              }
              ?>


              In the document, you’ll have tags for all the TVs:

              <h3>Assets</h3>
              [*Assets*]
              
              <h3>Assets-Snippets</h3>
              [*Assets-Snippets*]


              Bob’s your uncle. grin

                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
                works magic. thanks a lot uncle.
                  • 3749
                  • 24,544 Posts
                  Thank you!

                  I’m glad it worked. It was kind of fun to write. smiley
                    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 after playing with it couple days I can say it’s defiantly works smiley
                    I still need to create a new TV for each new manufacture dir I’m adding to the FTP but that’s ok.
                    The only other problem I see is that each page load in the manager now takes good 10 sec to load because of all the directory files processing.
                    Think I have no other choice but to create the clients pages a template of their own which then I’ll assign the products_x TVs to it only. then I’ll only need to wait on these pages.

                    *if only we could do ’add another’ to modx core File TV, sigh:
                      • 3749
                      • 24,544 Posts
                      You should be able to leave everything cached and just clear the cache whenever you add a new one. That should speed things up some.
                        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