We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9191
    • 20 Posts
    Is there a setTemplateVariable() function somewhere I’m not finding or do I just have to do the insert on the database manually?
      • 22303 MODX Staff
      • 10,725 Posts
      0.9.7 will introduce a complete, object-oriented API for working with all MODx content and data without resorting to SQL. For instance:
      <?php
      $content= 'My new TV value...';
      $tv= $modx->getObject('modTemplateVar', array ('name' => 'extra-content'));
      $tv->setValue(12, $content);
      ?>
      ... would set the value of a TV named extra-content to the value of $content for the document with id = 12.

      Until then, it’s fairly easy to abstract the logic of doing this into a function or class you can include and make use of in a snippet. Then you can simply replace the calls to that function or the implementation of that function when the new API is available. I believe there are a couple of components in development for 0.9.6 that do exactly this...