This snippet comes in handy for using getResource in a multi context setup. Thank you bwente for the help.
Snippet: GetIDByAlias
<?php
$resources = $modx->getObject('modResource', array('alias' => $alias, 'context_key' => $modx->context->key));
if ($resources == null) {
return;
} else {
return $resources->get('id');
}
Usage in a getResource call:
[[!getResources:default=`There are no items found.`?
&tpl=`yourTPL`
&parents=`[[GetIDByAlias? &alias=`your-alias-of-target-parent`]]`
&context=`[[*context_key]]`
&showHidden=`1`
&depth=`1`
&limit=`0`
&includeTVs=`1`
&tvPrefix=``
&processTVs=`1`
&includeContent=`0`
&sortby=`menuindex`
&sortdir=`ASC`
]]
This can help you get the correct parent ID across context if you have a duplicate page on another context. Works great for getResource calls that you are calling parents other then the current document your on.
[ed. note: orbitalalliance last edited this post 12 years, 7 months ago.]
It might be a good idea for getResource to have a parameter for &parentsID= along with &parentsAlias= that would be helpful for multicontext sites where you don't know the parentID.