Dropdown Input Type with @SNIPPET

I would like to use the dropdown input type in a repeater with @SNIPPET. Is there a way to pass some parameters to the snippet? According to the documentation, the snippet will receive two variables: $field, containing the current cbField object, and $input, containing an instance of the DropdownInput class.

I need to get the value of a specific tv from the resoure as well as the field ID so that I can use both in the snippet to build the JSON output for the dropdown. So I am assuming I would need to pass resource id and field id to the snippet.


No, it’s not possible to pass properties to it directly. If needed you can use a snippet that calls $modx->runSnippet() with some properties.

For your use cases, $modx->resource->get('id']) and $field->get('id') should do the trick.

hm, this works well for $field->get('id') but $modx->resource->get('id') breaks the output of my snippet, even the error won’t get pushed to the log.

Here is my code:

$field = $modx->getOption(‘field’, $scriptProperties, ‘’);
$input = $modx->getOption(‘input’, $scriptProperties, ‘’);
$output = “”;

$id = $field->get(‘id’);
$resid = $modx->resource->get(‘id’);

$output = array();
/* $output[] = array(
‘value’ => $resid,
‘display’ => $id,

$modx->log(modX::LOG_LEVEL_ERROR, ‘[TestCBDropDownSnippet] with ‘. $resid.’—’.$id);

return json_encode($output);`

I also tried $input->modx->resource->get('id') but this doesnt work either.

Hi! did you find a solution? I’m facing the same problem: I would like a dropdown related to current resource, but can’t find the way to retrieve the current doc id…


Hi Mara,

unfortunately not. I even wasn’t able to get the resource id in the dropdown class. I am hoping for a solution for one of the next releases, maybe an additional snippet input similar to the placeholder usage in the image field path option, which would be great.

It indeed appears that the resource is not made available on the dropdown options. I’ve just logged this in our tracker and we’ll look at correcting that in an upcoming version. Will update this topic!

$modx->resource is now available in the snippet. Update to 1.6.2 and if you run into any other issues let me know! :slight_smile:

1 Like