API:getTemplateVars
From MODx Wiki
[edit]
Overview
Returns an array of TV records.
$idnames - an array of template variable IDs or names that belong to the template the current document is using.
[edit]
Source Code
| File: | manager/includes/document.parser.class.inc.php |
|---|---|
| Line: | 1824 |
function getTemplateVars($idnames= array (), $fields= "*", $docid= "", $published= 1, $sort= "rank", $dir= "ASC") { return false; } else { // get document record if ($docid == "") { $docid= $this->documentIdentifier; $docRow= $this->documentObject; } else { $docRow= $this->getDocument($docid, '*', $published); if (!$docRow) return false; } // get user defined template variables $fields= ($fields == "") ? "tv.*" : 'tv.' . implode(',tv.', preg_replace("/^\s/i", "", explode(',', $fields))); $sort= ($sort == "") ? "" : 'tv.' . implode(',tv.', preg_replace("/^\s/i", "", explode(',', $sort))); if ($idnames == "*") $query= "tv.id<>0"; else $query= (is_numeric($idnames[0]) ? "tv.id" : "tv.name") . " IN ('" . implode("','", $idnames) . "')"; if ($docgrp= $this->getUserDocGroups()) $sql= "SELECT $fields, IF(tvc.value!='',tvc.value,tv.default_text) as value "; $sql .= "FROM " . $this->getFullTableName('site_tmplvars')." tv "; $sql .= "INNER JOIN " . $this->getFullTableName('site_tmplvar_templates')." tvtpl ON tvtpl.tmplvarid = tv.id "; $sql .= "LEFT JOIN " . $this->getFullTableName('site_tmplvar_contentvalues')." tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '" . $docid . "' "; $sql .= "WHERE " . $query . " AND tvtpl.templateid = " . $docRow['template']; if ($sort) $sql .= " ORDER BY $sort $dir "; $rs= $this->dbQuery($sql); for ($i= 0; $i < @ $this->recordCount($rs); $i++) { } // get default/built-in template variables foreach ($docRow as $key => $value) { "name" => $key, "value" => $value )); } return $result; } }
