We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17304 ☆ A M B ☆
    • 13 Posts
    Hi - hope someone can enlighten me:

    Is there any reason why this shouldn’t work? I’m trying to create a TV which lists all children documents with a specific template number in dropdown format

    The TV Option Values code is -
    @EVAL return $modx->runSnippet('getChildrenDropdown',array('docid'=>$_GET['id'],'tpl'=>'3'));


    And the getChildrenDropdown snippet code is -
    <?php
    /* Get the current document id */
    $docid = isset($docid) ? $docid : $_GET['id'];
    $tpl = isset($tpl) ? $tpl : "";
      
      
    $c = $modx->newQuery('modResource');  
    $c->where(array(  
       'parent' => $docid,
       'template' => $tpl,  
       'deleted' => false,    
    ));  
    $c->sortby('menuindex','ASC');  
    $c->limit(1000);  
    $documentArray = $modx->getCollection('modResource',$c); 
     
      $documentNames=array(); 
      $l_documents = 'Unassigned==||';
     
    /* Put the document names into the array  */
    foreach($documentArray as $document) {
        $documentNames[] = $document->get('pagetitle').'=='.$document->get('id');
    }
     
    /* Format the document names as a delimited string for the TV  */
      
     $l_documents .= implode("||",$documentNames);
     return $l_documents; 
    ?>​


    When I replace
    'parent' => $docid,
    in the snippet above with
    'parent' => '9',
    it works just fine

    ???
      • 17304 ☆ A M B ☆
      • 13 Posts
      I’m still having trouble with this... The general question here, I guess, is how do you refer to the current document’s id within a TV?
      I managed to get something like this to work in evolution, but I’m having trouble with a Revolution version.

      What if I need the current document’s children with a certain template number to appear in a TV? I tried with the snippet above...
      Can it be done with a @SELECT statement?

      I mean - something like: (TV Input Option Values)
      @SELECT modx_site_content.pagetitle as artist, modx_site_content.id as artistid FROM modx_site_content WHERE modx_site_content.template = 7 AND modx_site_content.parent = $_GET['id'] ORDER BY modx_site_content.menuindex)


      This doesn’t work in my case. Take the
      AND modx_site_content.parent = $_GET['id']

      clause out and it works, only I have a dropdown with all the site’s docs with template = 7...

      Would love some help from someone, I’ve spent hours trying to figure this one out

      Closest thing I found was in http://modxcms.com/forums/index.php/topic,26826.0.html, but, again, replacing the ’7’ in
      @eval global $modx; $childArr = $modx->getDocumentChildren(7); foreach($childArr as $child){$opArr[]=$child['pagetitle']."==".$child['id'];} return $opArr;

      with
      $_GET['id']

      doesn’t work...
        • 3749
        • 24,544 Posts
        It seems to me that what you’re trying should work. I don’t know why it doesn’t.

        You might try creating a diagnostic @EVAL TV that has the code:

        return print_r($_GET,true);


        to see what’s in the $_GET array. Then try it with $_POST and $_REQUEST.
          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