On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I looked an searched, but couldn’t find an answer to my question:

    How can I get an array of all TV-content present on a page?
    something like
    "$contentarray = $modx->getTemplateVarOutput(*,$docID);"
    As far as I can see I always have to know the name of the TV to ask for its content.
    But if I do not know the names and just want the rendered output of all TVs for a page?

    any clues?

    • Have a look at the (prefix)site_tmplvar_contentvalues table in the database, I’m pretty sure this is where the information you seek is stored.

      You could create a custom query to grab only the TV content for the doc which would be something like the code below:
      Note this example only counts the number of TVs for the document which has this snippet, but you can modify as needed:

      $output ="";
      $sql = "SELECT * FROM ".$modx->dbConfig['dbase'].".".$modx->dbConfig['table_prefix']."site_tmplvar_contentvalues WHERE contentid='".$modx->documentObject['id']."'";
           $rs = @$modx->dbQuery($sql);
           $limit = @$modx->recordCount($rs);
             if($limit > 0 ){
                 $output .="There are ".$limit." TVs for this document";
                 $output .="No TVs found";
       return $output;
        http://frsbuilders.net (under construction) forum for evolution
      • Thanks breezer! So, pulling it directly from the DB would be the way?
        I thought that a cominbation of getTemplateVars to get an array of TVnames and then cycling it using getTemplateVarOutput could do this job. Seemed a bit too complicated.
        Ok, then, at least I have an option now, thanks again!
        • Definitely NOT the recommended approach. Pulling things directly from the database is bypassing the API and asking for future upgrade issues. $modx->getTemplateVarOutput(’*’, $docId) will retrieve an array of the TV records from the db for you, returning the the data as an array of arrays, keyed with the tv names applicable to that document. Each TV array includes all the data necessary to process it. The only problem is, you then have to process that TV data as the parser would to render it properly, especially if using @ bindings or widgets. This is being addressed by the new object-oriented API, so that you can simply get the template vars for a doc and simply be able to render them with another API call the same way the parser would.

          Until then, you’ll need to look at the document.parser.class.inc.php and duplicate the TV rendering logic.
          • Aha, thought so that direct db-access would not be recommended wink
            So: the only thing I was missing were the ’’ around the * ? (I simply could not imagine that wildcards would work in function-calls like this..)
            Fine! And, because I’m not interested in capturing other docs (@DOCUMENT) or re-rendering widget stuff, that’s all I need. I just want access to normal content for the new version of my PageKeywords-snippet.
            Thanks Jason!
            • Quote from: silent at Aug 17, 2006, 05:27 PM

              So: the only thing I was missing were the ’’ around the * ? (I simply could not imagine that wildcards would work in function-calls like this..)

              Yep, and it’s a hard-coded option, i.e. * = all TV’s, so not really a wildcard per se; otherwise you specify an array of specific TV names to return the values for.