Like just about everything in the MODX GUI, you can access Template Variables and their values via the MODX API. This relies on the xPDO method getObject and related functions, but we demonstrate some examples here because it relates directly to Template Variables.
Let's say we have a TV named 'bio', and we're going to retrieve page id 123 that uses this TV. Here's what our Snippet might look like:
Use setTVValue to save a new value to a TV. Unlike some other xPDO API methods, this method stores values to the database immediately, so you do not need to invoke a separate call to a save() method.