API:getTemplateVarOutput
From MODx Wiki
API Function Definition:
getTemplateVarOutput
- Versions
- > 0.9.2 ?
- Return Values
- Success: Selected TVs
- Fail: false
- Data Type
- array
- Object Hierarchy
- DocumentParser
array getTemplateVarOutput($idnames[, $docid=, [$published='1']]);
- $idnames - Array of TV names to select (enter '*' for all TVs in the document).
- $docid - Document ID to retrieve from (defaults to current document).
- $published - Search published or unpublished documents.
Returns an associative array containing TV rendered output values.
Examples
$tv_value = $modx->getTemplateVarOutput($tv_string);
Will return an associative array of the TV and its value.
So $tv_value[$tv_string] gives the value associated to that TV
Working Example
Live Example: Suppose you have a TV named "price" for a documentID "2" then you will get the value of its as below :
$tvPr = $modx->getTemplateVarOutput(array("price"),$docid='2',$published=1); echo $tvPr['price'];
Related Functions
Function Source
| File: | manager/includes/document.parser.class.inc.php |
|---|---|
| Line: | 1876 |
return false; } else { $result= $this->getTemplateVars($vars, "*", $docid, $published, "", ""); // remove sort for speed if ($result == false) return false; else { $baspath= $this->config["base_path"] . "manager/includes"; include_once $baspath . "/tmplvars.format.inc.php"; include_once $baspath . "/tmplvars.commands.inc.php"; $row= $result[$i]; // to-do needs fixing when getting tvs from other pages $replace_richtext= ""; $richtexteditor= ""; $w= "100%"; $h= "300"; $output[$row['name']]= getTVDisplayFormat($row['name'], $row['value'], $row['display'], $row['display_params'], $row['type'], $docid); } return $output; } } }