One parent page
|
---Three children pages (ids=12, 24, 34)
|
---Each has a TV with list of keywordsin the parent page I want to display a paragraph of all three lists into a single list.?
[[getResourceField? &id=`12` &field=`myTV` &processTV=`1` ]] [[getResourceField? &id=`24` &field=`myTV` &processTV=`1` ]] [[getResourceField? &id=`34` &field=`myTV` &processTV=`1` ]]
<p>[[!KeyWordList]]</p>
<?php
/* KeyWordList snippet */
$docId = $modx->resource->get('id');
$tvId = 12; /* set to the ID of your TV */
$childIds = $modx->getChildIds($docId);
$c = $modx->newQuery('modTemplateVarResource');
$c->where(array(
'tmplvarid' => $tvId,
'contentid:IN' => $childIds,
));
$tvts = $modx->getCollection('modTemplateVarResource', $c);
$list = '';
$prefix = '';
foreach ($tvts as $tvt) {
$list .= $prefix . $tvt->get('value');
$prefix = ',';
}
return $list;
<?php
/* KeyWordList snippet */
$docId = $modx->resource->get('id');
$tvId = 12; // set to the ID of your TV
$childIds = $modx->getChildIds($docId);
$classname = 'modTemplateVarResource';
$c = $modx->newQuery($classname);
$c->where(array(
'tmplvarid' => $tvId,
'contentid:IN' => $childIds,
));
$list = '';
if ($tvts = $modx->getCollection($classname, $c)) {
$prefix = '';
foreach ($tvts as $tvt) {
$list .= $prefix . $tvt->get('value');
$prefix = ',';
}
}
return $list;
donshakespeare's method looks fine, but I think this will do it with one query and no extra function calls (untested):
<p>[[!KeyWordList]]</p>
<!--?php /* KeyWordList snippet */ $docId = $modx--->resource->get('id'); $tvId = 12; /* set to the ID of your TV */ $childIds = $modx->getChildIds($docId); $c = $modx->newQuery('modTemplateVarResource'); $c->where(array( 'tmplvarid' => $tvId, 'contentid:IN' => $childIds, )); $tvts = $modx->getCollection('modTemplateVarResource', $c); $list = ''; $prefix = ''; foreach ($tvts as $tvt) { $list .= $prefix . $tvt->get('value'); $prefix = ','; } return $list;
This assumes that you can use the raw output of the TVs, which is significantly faster. That should be fine since they're just text.
<?php
/* KeyWordList snippet */
$docId = $modx->resource->get('id');
$tvId = 12; // set to the ID of your TV
$childIds = $modx->getChildIds($docId);
$classname = 'modTemplateVarResource';
$c = $modx->newQuery($classname);
$c->where(array(
'tmplvarid' => $tvId,
'contentid:IN' => $childIds,
));
$output = '';
if ($tvts = $modx->getCollection($classname, $c)) {
$list = '';
foreach ($tvts as $tvt) {
$list = $tvt->get('value');
$output .= "\n<ul>";
$terms = explode(',', $list);
foreach ($terms as $term) {
$output .= "\n <li>" . trim($term) . '</li>';
}
$output .= "\n</ul>";
}
}
return $output;