We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18654
    • 191 Posts
    Any idea why the following code won’t produce any output when there are existing Template Variables?

    	$tvCriteria = $modx->newQuery('modElement', array(
    		'class_key' => 'modTemplateVar'
    	));
    	$tvVars =  $modx->getCollection('modElement', $tvCriteria);
    	foreach ($tvVars as $tvVar) { 
    	echo 'test result set';
    	$test =  $tvVar->toArray();
    	print_r($test);
    	}
    

      God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.
      • 28215
      • 4,149 Posts
      Use modTemplateVar as the class name, omit the class_key reference - this is different than modStaticResource, as modTemplateVar (and modSnippet, modChunk, etc) are stored in different tables and are different types of relationships - they are extended classes moreso than derivatives.

      Your code would look like so:

      $tvVars =  $modx->getCollection('modTemplateVar');
      foreach ($tvVars as $tvVar) { 
      	echo 'test result set';
      	$test =  $tvVar->toArray();
      	print_r($test);
      }
      
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 18654
        • 191 Posts
        That works perfect - Thanks!
          God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.