This should do what you need:
$output='';
$idname=$modx->getTemplateVarOutput('name',$modx->documentIdentifier);
if($idname['name']!='') $output.='<p>'.$idname['name'].'</p>';
return $output;
Sometimes it can be confusing that this function returns an array (which is why you need to refer to your name value as $idname[’name’]). But once you realize that it’s pretty straightforward (and you can get the values of several TVs with one line of code). The only problem that I’ve had with this particular function is that if you use it to get the output of a TV with multiple values (listboxes and checkboxes), it returns them all as one long string with no separators, so if you need to do that don’t try to use this function (a regular query works better).
Thank you Zap, that’s what I was looking for.