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

    Just like the title says: "Can you change the value of a TV in a snippet? And how?"

    thanks
      • 23324
      • 40 Posts
      Found the solution myself. I can make a connection with the database and change the value to whatever i want...

      Just thought there might be something easier...
        • 1778
        • 659 Posts
        Hello,
        Something like that ?

        <?php
        // get ID of the current document
        $docID = $modx->resource->get('id');
        
        // get the TV Color in the current doc
        $tv = $modx->getObject('modTemplateVar',array('name'=>'Color'));
        
        $newValue = "red";
        
        // Set the tv Color with new value
        $tv->setValue($docID, $newValue);
        $tv->save();
         ?>