Multiselect TV: Only show resources from actual context

So why don’t you just use a resourcelist-TV then?

With the settings:

  • Parents = 2,4
  • Depth = 1
  • Include Parents = No
  • Limit to Related Context = Yes

With a multiselect-TV you probably have to use a @CHUNK binding (instead of @SELECT).

For example use this in the field Input Option Values.

@CHUNK listResources

Then create a chunk listResources that calls a snippet.

[[listResources]]

Then create a snippet listResources with code like this to create the list.

<?php
$current_ctx = $modx->resource->get('context_key'); //context of current resource

$q = $modx->newQuery('modResource', array('parent:IN' => array(2,4), 'context_key' => $current_ctx, 'deleted' => 0));
$q->select(array('id','pagetitle'));
$q->sortby('menuindex','ASC');
$resources = $modx->getCollection('modResource', $q);
$output = array();
foreach ($resources as $resource) {
   $output[] = $resource->get('pagetitle') . '==' . $resource->get('id');
}
return implode('||',$output);
1 Like