This question has been answered by BobRay. See the first response.
$alias='some alias';
$context = 'some context';
$resource = $modx->getObject('modResource', array('alias' => $alias, 'context_key' => $context));
if ($resource) {
return $resource->getContent();
}$alias='some alias';
$resource = $modx->getObject('modResource', array('alias' => $alias));
if ($resource) {
return $resource->getContent();
}If I'm understanding you, it would take a custom snippet, but you shouldn't need the ID. If you know the alias and the context you want, you can to this:
$alias='some alias'; $context = 'some context'; $resource = $modx->getObject('modResource', array('alias' => $alias, 'context_key' => $context)); if ($resource) { return $resource->getContent(); }
If the alias is unique (i.e., not duplicated in other contexts), you can do this instead:
$alias='some alias'; $resource = $modx->getObject('modResource', array('alias' => $alias)); if ($resource) { return $resource->getContent(); }
Note that you'll be getting the raw content field of the resource. Any MODX tags it contains won't be processed.
<?php
$alias='form-contact';
$context = $modx->context->key;
$resource = $modx->getObject('modResource', array('alias' => $alias, 'context_key' => $context));
if ($resource) {
return $resource->getContent();
}