We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13135
    • 30 Posts
    I have a folder containing resources that are boxes of content to go the side column of a site. (Evo 1.0.5)

    I was using TV based chunks to grab chunks and then the client could simply check what boxes to appear in the side column on each page.
    However, I would rather not have the client editing chunks.

    I would like to use @DIRECTORY to output the documents in the folder /side-boxes/ (in root but hidden from the menu) and then output the check boxes just as TV based chunks would.

    However, when I create a Checkbox TV with @DIRECTORY side-boxes/ in the Input Options Values and with a delimited list widget and value(,)
    it just outputs a path from the server root to the folder: /var/www/vhosts/domainname.co.uk/httpdocs/side-boxes/

    There is little documentation on this... any help?

    Thanks...
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Resources are stored in the database, @DIRECTORY gets a list of files from the given file system directory. Do not confuse the virtual "folder" structure of the Resource Tree with the file system. Resources are stored flat in one table of the database, and the Tree structure is built from each resource’s "parent" field. Wayfinder (and many other listing-type snippets) uses the field as well to generate its nested lists.
        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
        • 13135
        • 30 Posts
        Hi,

        ok, but using ditto would not enable me to use a checkbox TV applied to each template, which the client can then use to apply certain boxes to the side column of the page that they are editing.

        I would have to use a checkbox TV on each side box page resource (rather than the page itself) to select each page that the box appears on, and then use ditto to filter by this TV. This list of pages to apply to would not be dynamically generated either...

        I know this can be done using @binding or possibly a snippet/plugin combo, but i am not sure how... do you have any documentation or forum threads that could help?


        To recap... I need a check box TV applied to each of the main website pages templates, so that the client can tick which side-column boxes they want to appear on that page. The list of side column boxes will dynamically generated from a folder (hidden from the menu, but in the resource tree) which contains the contents of each box as a page resource. This way the client can generate their own side column boxes and edit them as though they are the same as any other page.

        Any ideas?

        Thanks...

          • 13135
          • 30 Posts
          OK, i have figured out how to do this using @EVAL, a snippet called docOptioner and ditto:

          1 - Create a snippet called DocOptioner (this grabs the child docs from a specified parent id and outputs them into manager to be selected.
          ):
          <?php
          //specify page id you want to get data for
          $root = $root;
          $depth = $depth;
          $exclude = preg_split('~\s*,\s*~', $exclude);
          $content = array();
          
          foreach ($modx->getChildIds($root,$depth) as $childID)
          {
              if (in_array($childID, $exclude))
              {
                  continue;
              }
             
              $child = $modx->getTemplateVarOutput(array('menutitle','parent','pagetitle'), $childID);
             
              if ((empty($child['menutitle']) && empty($child['pagetitle'])) || empty($child['parent']))
              {
                  continue;
              }
             
              if ($depth > 1)
              {
                  if ($child['parent'] == $root || in_array($child['parent'], $exclude))
                  {
                      continue;
                  }
                 
                  $parent = $modx->getTemplateVarOutput(array('menutitle'), $child['parent']);
              }
             
              $content[] = $child['pagetitle'] . '==' . $childID;
          }
          
          return implode('||',$content);
          ?>


          3 - Then Create Template Variable:

          Input type: check box
          Input option values:

          @EVAL return $modx->runSnippet(’docOptionifier’, array(’root’ => 15, ’depth’ => 2, ’exclude’ => "53,333", ’option’ => ’id’));

          Note: Update ’root’ => 15 to the id of the your folder.
          Depth - you can specify how far down the document tree to search for options.
          Exclude - you can exclude certain documents (by id) from being output as option by the snippet.

          4 - Associate TV with template

          5 - create a ditto call in the template where you want the boxes to appear:
          [[Ditto? &documents=`[*name of TV*]` &depth=`1` &tpl=`ChunkNameToFormatOutput` &orderBy=`menuindex ASC`]]

          DONE!
            • 13135
            • 30 Posts
            Questions:
            - how can i change the initial post title to change @DIRECTORY to @EVAL (to make sure that people looking for this can find it more easily)?
            - How can i also mark it as [SOLVED] ?

            Thanks...
              • 3749
              • 24,544 Posts
              Quote from: iskri at Feb 14, 2011, 09:19 AM

              Questions:
              - how can i change the initial post title to change @DIRECTORY to @EVAL (to make sure that people looking for this can find it more easily)?
              - How can i also mark it as [SOLVED] ?

              Thanks...

              Post a reply and change the subject line at the top of the reply form.
                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
                • 13135
                • 30 Posts
                Thanks!
                  • 18137
                  • 3 Posts
                  Hi, just want to follow up for anyone else who finds this solution helpful. I couldn’t get this to work without a crucial modification: The template variable you create HAS to have an output widget defined as "delimited list", with a comma as the delimiter. It’s needed so the Ditto call can handle more than one id value in the TV output. Without the output widget set the Ditto call works if only one document is listed, and then fails with more because the TV output is just a string of docids with no delimiter!

                  Thanks for the awesome solution to a big problem!

                  (A)