Input type: resource-id?


input-type ‘link’ does provide a link to a resource, ok.
but I want to get the id of a resource (to provide it as a parameter to getResources).

cbGetField &returnAsJSON does return the id within .link-property,
but cbGetField always returns the path instead of the id!

why does it not have [[~[[+link]]]] in template for the field instead of [[+link]] ?
it would be much more flexible! (or even a value of [[+id]] would be fine!)

so my question:
how do I let the user/editor choose a resource and return the id of this resource for further processing ?

it’s not an option to let the user/editor find the id (yes, it always shows in brackets in the resource-tree) and just enter that number!



If you just want the ID, you can use the [[+link_raw]] placeholder. Here’s the documentation in the link input:

Does that help?

yes, that’s it. just the resource-id.

but regarding the documentation: “the link without protocols or link tag”, I didn’t expect it to be the ID.

thanks a lot.


BTW: my approach was a bit more complex

I wrote a snippet: [[_cbGetLinkID? &field=123]]

$fld = $modx->getOption('field', $scriptProperties, 0, true);
$json = $modx->runSnippet('cbGetFieldContent',array('field' => $fld, 'returnAsJSON' => 1));
list($field) = json_decode($json); 
echo $field->link;

[[+link_raw]] may also contain an email address or url if that’s what the user entered in the link field. That’s why [[+link]] returns the generated url instead of just the resource ID, as [[+link]] will always have a full url including protocols.

Alternative solutions could be to use the dropdown input in 1.5 or the third party cbResourceSelect input instead of a link.