if (empty($input)) { return ''; } $tpl = $modx->getOption('tpl',$scriptProperties,'relatedPagesTpl'); if ($modx->getChunk($tpl) == '') { return 'Missing Tpl!'; } $ids = explode(',', $input); $output = array(); foreach ($ids as $key => $value) { $resource = $modx->getObject('modResource',array('published' => 1,'id' => $value)) [b]&& $modx->getObject('modTemplateVar',array('name'=>'tvname1'))[/b]; if ($resource instanceof modResource) { $output[] = $modx->getChunk($tpl,$resource->toArray()); } } return implode('',$output);
This question has been answered by rcarnrick. See the first response.
$tvId = 12; /* Id of the TV */ $tvr = $modx->getObject('modTemplateVarResource', array('contentId' => $resource->get('id'), 'tmplvarid' => $tvId)); $tvValue = $tvr->get('value');
$tvr = $modx->getObject('modTemplateVarResource', array('contentId' => $resource->get('id'), 'tmplvarid' => $tvId)); if ($tvr) { $tvValue = $tvr->get('value'); } else { $tv = $modx->getObject('modTemplateVar'); $tvValue = $tv->get('default_text'); }
if (empty($input)) { return 'This article is so unique, that we couldn\'t find anything related to it!'; } $tpl = $modx->getOption('tpl',$scriptProperties,'relatedPagesTpl'); if ($modx->getChunk($tpl) == '') { return 'We found some related pages, but don\'t know how to present it.'; } $ids = explode(',', $input); $output = array(); foreach ($ids as $key => $value) { $resource = $modx->getObject('modResource',array( 'published' => 1, 'id' => $value)); if ($resource instanceof modResource) { $ta = $resource->toArray(); $ta = array_merge($ta,$resource->getTemplateVars()); $output[] = $modx->getChunk($tpl,$ta); } } return implode('',$output);