Some news,
here is the code to get values for second TV according to selected value in first TV
@EVAL $docID = $modx->getDocumentIdentifier('id');
$templateTest = $modx->getTemplateVar('templateTest','*', $docID);
if(strlen($templateTest['value'])>0){
$sql= "SELECT name, id FROM modx_site_tmplvars LEFT JOIN modx_site_tmplvar_templates ON templateid=tmplvarid WHERE templateid=".$templateTest['value'];
$rs = $modx->db->query($sql);
while($myvalues = $modx->db->getRow($rs)) {
$value .= $myvalues['name']."==".$myvalues['id']."||";
}
return substr($value,0,-2);
}
The code works fine as a snippet but send me back an error when pasted in input values
Parse error: parse error, unexpected T_IS_EQUAL in /Users/fredm/Sites/moretto/manager/includes/tmplvars.commands.inc.php(51) : eval()’d code on line 1
:-)
EDIT: after some investigations the error comes from this part of the code
$value .= $myvalues['name']."==".$myvalues['id']."||";
If I remove the dot before "=" here --> "$value .= ", the error disappears.
isn’t that odd !!!!
EDIT2: the variable has to be affected first with $value="";
the working code:
@EVAL $docID = $modx->getDocumentIdentifier('id');
$templateTest = $modx->getTemplateVar('templateTest','*', $docID);
if(strlen($templateTest['value'])>0){
$sql= "SELECT name, id FROM modx_site_tmplvar_templates LEFT JOIN modx_site_tmplvars ON tmplvarid=id WHERE templateid=".$templateTest['value']
$rs = $modx->db->query($sql);
$value="";
while($myvalues = $modx->db->getRow($rs)) {
$value .= $myvalues['name']."==".$myvalues['id']."||";
}
return substr($value,0,-2);
}