Multiselect TV: Only show resources from actual context

Hi,
I have a multiselect-TV hosting resources from two parents which are in two different contexts:

@SELECT pagetitle, id FROM modx_site_content WHERE parent IN (2,4)

parent #2 is in context web
parent #4 is in context lang

I would like to restrict my multiselect-TV to only show the resources from the actual context like you can do with a resourcelist-TV using limitRelatedContext. How is this possible?

Thanks in advance.

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

Because I want to select multiple resources and a resourcelist-TV is a single-select dropdown afaik. Or am I wrong here?

Thank you for your code, trying it atm.

In this case you probably can use the SuperBoxSelect extra.

https://modx.com/extras/package/superboxselect

1 Like

Never heard of that, will try it out.
Your code works perfectly fine, thank you very much!

SuperBoxSelect has some advantages over a multiselect-TV.

It uses paging (with AJAX) which is great if you have a lot of resources to choose from and you can also reorder the selected items which is neat.

I see. Will definitely check out SuperBoxSelect, thanks for the tip and your code, @halftrainedharry !

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.