Hello
I'm also using the tutorial and have the same problems as the OP. Following this thread I've been able to get the TVs from various resources to be pulled in but cannot get the checkbox list to show multiple parents. I noticed Zorba had the same problem and resolved it by
Got it! The list of check boxes is back - I found the wrong ID being referenced in the listMyResources snippet.
but I can only seem to get one of three parents I wish to use to show. I'm sure it'll be something very simple but I can't see what I'm missing?
I realise I'm only calling one parent in the listProducts snippet but thought that was just a fallback if it can't find the children of other parents. When I change that parent ID to 4, 5 or 6 the checklist shows the corresponding children but not all three parents together. Does that need to be an array too?
Here are my pieces of code:
ListProducts Snippet
$parent = $modx->getOption('parent',$scriptProperties,5);
$parentObj = $modx->getObject('modResource',$parent);
if (!($parentObj instanceof modResource)) { return ''; }
$resArray = $parentObj->getMany('Children');
$resources = array();
foreach($resArray as $res) {
if ($res instanceof modResource) {
$resources[] = $res->get('pagetitle') . '==' . $res->get('id');
}
}
$out = implode("||",$resources);
return $out;
RelatedProducts snippet
if (empty($input)) { return 'This article is so unique, that we couldn\'t find anything related to it!'; }
$tpl = $modx->getOption('tpl',$scriptProperties,'relatedProductsTpl');
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();
$tvs = $resource->getTemplateVars();
foreach ($tvs as $tv) {
$ta[$tv->get('name')] = $tv->get('value');
}
$output[] = $modx->getChunk($tpl,$ta);
}
}
return implode('',$output);
relatedProducts TV input
@EVAL return $modx->runSnippet('listProducts',array('parent:IN' => array(4,5,6)));
Template snippet
[[relatedProducts? &input=`[[*relatedProducts]]` &tpl=`relatedProductsTpl`]]
relatedProductTpl chunk
<div class="productSliderItem" style="background: url('[[+productBackgroundImage]]') no-repeat; background-size:auto 100%;">
<a href="[[~[[+id]]]]" title="[[+pagetitle]]">
<div class="shake shake-slow">
<img src="[[+productPack]]" />
</div>
<div class="productSliderTitle">
<p>[[+pagetitle]]</p>
</div>
</a>
</div>
Thanks in advance
[ed. note: cottoncreative last edited this post 9 years, 6 months ago.]