We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • thanks Susan, yes I have been following the thread, am now clear on it. smiley Very interested and especially thinking about the input option values being an @select ...binding? Thinking about the TV bindings in Evo.

    http://wiki.modxcms.com/index.php/@SELECT_Binding

    and I found this, which might be helpful.

    https://gist.github.com/3105800
      ________

      Anne
      Toad-in-Chief
      Red Toad Media - Web Design, Louisville KY
      Hear me tweet: http://www.twitter.com/redtoadmedia
      "Bring on the imperialistic condiments." - Rory Gilmore
    • discuss.answer
      You can do this by defining a Listbox TV, and then using the EVAL binding to supply it with input options.

      Here's a Snippet I put together:

      <?php
      /**
       * Supports listing out the contents of a single folder that can contain pages or 
       * folders up to 2 levels deep only, e.g. if you have a folder of pages (one page
       * for one "category") :
       *
       * Categories
       *			+--- SubCategory1
       *			|		+--- EndCategory1
       *			|		+--- EndCategory2
       *			|
       *			+--- SubCategory2	
       *			+--- SubCategory3	
       */
       
      // Get top-level categories
      
      $criteria = array();
      $criteria['parent'] = (int) $parent;
      $criteria['deleted'] = '0';
      $criteria['published'] = '1';
      $criteria['hidemenu'] = '0';
      
      
      $query = $modx->newQuery('modResource', $criteria);
      
      $resources = $modx->getCollection('modResource', $query);
      
      $output = array();
      
      $top_level_ids = array();
      foreach ($resources as $r) {
      	$output[] = $r->get('pagetitle') .'=='.$r->get('id');
      	// Get sub-levels
      	if ($r->get('isfolder')) {
      		$criteria['parent'] = $r->get('id');
      		$query = $modx->newQuery('modResource', $criteria);
      		$sub_resources = $modx->getCollection('modResource', $query);
      		foreach ($sub_resources as $sr) {
      			$output[] = ' ---- '.$sr->get('pagetitle').'=='.$sr->get('id');	
      		}
      	}
      }
      
      return implode('||',$output);


      And then put this into your TV's Input Option Values (replace the parent attribute with the ID of the parent folder whose contents you want to display):

      @EVAL return $modx->runSnippet('nameOfSnippet',array('parent'=>2));
      • Fantastic! Thanks!
          Ben Morrison
          Hacking templates to pieces since 2003
          • 19328
          • 433 Posts
          Thanks so much Everett, this is great!
            • 19328
            • 433 Posts
            I extended Everett's snippet a little, to include the following:
            - 4 levels
            - using the ⌊ sign to indicate next level
            - adding the id after the pagetitle
            - option to exclude ID's on each level.

            I'm not a php expert so this might be done in a more efficient way, but it works for me smiley
            I thought I'd post it here for others who might be interested.

            <?php
            /**
             * Supports listing out the contents of a single folder that can contain pages or 
             * folders up to 2 levels deep only, e.g. if you have a folder of pages (one page
             * for one "category") :
             *
             * Categories
             *          +--- SubCategory1
             *          |       +--- EndCategory1
             *          |       +--- EndCategory2
             *          |
             *          +--- SubCategory2   
             *          +--- SubCategory3   
             */
              
            // Get top-level categories
             
            $criteria = array();
            $criteria['parent'] = (int) $parent;
            $criteria['deleted'] = '0';
            $criteria['published'] = '1';
            $criteria['hidemenu'] = '1';
            
            $query = $modx->newQuery('modResource', $criteria);
            
            // id's that should not be included on root level
            $query->where(array('id:NOT IN' => array(186,26,119)));
            
            $resources = $modx->getCollection('modResource', $query);
             
            $output = array();
             
            $top_level_ids = array();
            foreach ($resources as $r) {
                
                // OUTPUT LEVEL 1
                $output[] = $r->get('pagetitle') .' ('.$r->get('id').')=='.$r->get('id');
                // Get sub-levels
                if ($r->get('isfolder')) {
                    $criteria['parent'] = $r->get('id');
                    $query = $modx->newQuery('modResource', $criteria);
            		
            		// id's that should not be included on this level
            		$query->where(array('id:NOT IN' => array(142,165)));
            
                    $sub_resources = $modx->getCollection('modResource', $query);
                    foreach ($sub_resources as $sr) {
                        
                        // OUTPUT LEVEL 2
                        $output[] = '   ⌊ '.$sr->get('pagetitle').' ('.$sr->get('id').')=='.$sr->get('id'); 
                        
                        if ($sr->get('isfolder')) {
                            $criteria['parent'] = $sr->get('id');
                            $query = $modx->newQuery('modResource', $criteria);
            				// id's that should not be included on this level
            				$query->where(array('id:NOT IN' => array(163)));
            
                            $sub_sub_resources = $modx->getCollection('modResource', $query);
                            foreach ($sub_sub_resources as $ssr) {
                                
                                // OUTPUT LEVEL 3
                                $output[] = '       ⌊ '.$ssr->get('pagetitle').' ('.$ssr->get('id').')=='.$ssr->get('id'); 
                                
                                if ($ssr->get('isfolder')) {
                                    $criteria['parent'] = $ssr->get('id');
                                    $query = $modx->newQuery('modResource', $criteria);
            						
            						// id's that should not be included on this level
            						$query->where(array('id:NOT IN' => array(171)));
            
                                    $sub_sub_sub_resources = $modx->getCollection('modResource', $query);
                                    foreach ($sub_sub_sub_resources as $sssr) {
                                        
                                        // OUTPUT LEVEL 4
                                        $output[] = '           ⌊ '.$sssr->get('pagetitle').' ('.$sssr->get('id').')=='.$sssr->get('id'); 
                             
                                    }
                                }                    
                            }
                        }            
                    }
                }
            }
             
            return implode('||',$output);



            EDIT: while this works great in the list, a selected item is shown as & nbsp ; ... etc. which is not so good. Probably the reason Everett used simple dashes!
              • 36996
              • 211 Posts
              It can be done this way:
              @SELECT pagetitle, id FROM modx_site_content WHERE parent=35

              Here's the source - http://www.sepiariver.ca/blog/modx-web/modx-quick-tip-easy-multi-select-resource-list-tv
              • nir-z: that query works for 1 level (i.e. get children), but the code here is intended to traverse down into deeper levels (i.e. get grandchildren, great-grandchildren, et al).
                  • 36996
                  • 211 Posts
                  Got it, thanks
                    • 17412
                    • 270 Posts
                    This is great. Is there a way to add an empty first item to the TV resource list, so by default, no resource is pre-selected?

                    Update, this can be added when you call the snippet as such

                    @EVAL return '==||' . $modx->runSnippet('snippetNameHere',array('parent'=>0));
                    [ed. note: lokust last edited this post 8 years, 4 months ago.]
                      • 3749
                      • 24,544 Posts
                      This should be a tiny bit more efficient:

                      $criteria = array(
                          'parent' => (int) $parent,
                          'deleted' => '0',
                          'published' = '1',
                          'hidemenu' = '1',
                      );


                      I was thinking that you might be able to make it much shorter by using:

                      $docs = $resource->getMany('Children');


                      or

                      $docIds = $modx->getChildIds($docId);



                      Those will get all grandchildren as well, but if you need to know the level of each resource, your method might be better.
                        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