API:getTemplateVarOutput

From MODx Wiki
Jump to: navigation, search
 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
  1. function getTemplateVarOutput($idnames= array (), $docid= "", $published= 1) {
  2. if (count($idnames) == 0) {
  3. return false;
  4. } else {
  5. $output= array ();
  6. $vars= ($idnames == '*' || is_array($idnames)) ? $idnames : array ($idnames);
  7. $docid= intval($docid) ? intval($docid) : $this->documentIdentifier;
  8. $result= $this->getTemplateVars($vars, "*", $docid, $published, "", ""); // remove sort for speed
  9. if ($result == false)
  10. return false;
  11. else {
  12. $baspath= $this->config["base_path"] . "manager/includes";
  13. include_once $baspath . "/tmplvars.format.inc.php";
  14. include_once $baspath . "/tmplvars.commands.inc.php";
  15. for ($i= 0; $i < count($result); $i++) {
  16. $row= $result[$i];
  17. // to-do needs fixing when getting tvs from other pages
  18. $replace_richtext= "";
  19. $richtexteditor= "";
  20. $w= "100%";
  21. $h= "300";
  22. $output[$row['name']]= getTVDisplayFormat($row['name'], $row['value'], $row['display'], $row['display_params'], $row['type'], $docid);
  23. }
  24. return $output;
  25. }
  26. }
  27. }

Notes

See Also: http://modxcms.com/gettemplatevaroutput.html

Personal tools