We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29860
    • 59 Posts
    Hi

    I have a site that has documents with a specific TV used across different templates. Is there a way for me to query through the API to get all values in this TV? Or would I have to traverse through the document tree in finding out the existing of this TV?
      • 31037
      • 358 Posts

      I used this for something similar, perhaps not that pretty but does the work:

            
       
        $children = $modx->getChildIds(20); //20 is the parent i needed children tvs from
           
             foreach ($children as $child) {
              
                  $tv = $modx->getObject('modTemplateVar',array('name'=>'thenameoftheTV'));
                  
                  /* get the raw content of the TV */
                  $rawValue = $tv->getValue($child);
                  $arr_rawValues[] = $rawValue;
             } 
      
            $arrUnique = array_unique($arr_rawValues);
            
            foreach ($arrUnique as $value) { //Do something }

        • 3749
        • 24,544 Posts
        I’m guessing somewhat here, but try this:

        <?php
        $intersects = $modx->getCollection('modTemplateVarResource, array('templvarid'=>$id));
        
        foreach($intersects as $intersect) {
        
            $tv = $modx->getObject('modTemplateVar', $intersect->get('templvarid'));
            $output .= <br />'Resource ID: ' . $intersect->get('contentid');
            $output .= '<br /'>'Processed TV VALUE: ' . $tv->renderOutput($intersect->get('contentid'));
            $output .=  '<br /'>'Raw TV VALUE: ' . $tv->getValue($intersect->get('contentid'));
        }
          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