ParentId is a value that comes from the form.
This works, but only if this parent resource is published. Otherwise, parent is set to zero and the resource appears in the root. Is this normal behavior? Is it possible to set the parent to an unpublished resource?
Also just for clarification the parent resource in script properties is from the active resource from which the snippet is called. You could call the resource parent object directly as well as based on your posted source we are not certain to how that variable is getting populated.
To get a resources parent you can use the resource object get method, again as noted this will return the pages parent from where the snippet is being called on.
$parentId = $modx->resource->get('parent');
Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
Visit CharlesMx.com for latest news and status updates.
Ai, now I feel stupid. I tested it again today and now it works just like it should. Yesterday I tried several times and the new resource ended up in the root every time I used the id of a unpublished resource as parent. I must have been doing something else wrong, but I can't figure out what could have caused it.
Thank you Bruno, Jason and Charles for your help and suggestions! I use a select box on the form with the id's of existing resources as values. The user can choose a resource in this list, and this id gets set as the parent when creating the new resource. Your suggestions did make me realize that I need to have a contingency plan when for some reason the parent ID isn't set in the form. Thanks!