I did end up using getResources in conjunction with your suggestion. Works
perfectly. I am doing a
LOT of assumption IMO by comparing pagetitle. I would like to come up with a better more fool-proof method of getting the resource other than by pagetitle. I also need to go back and clean up/sanitize the $_POST data to reduce any unwanted data coming across.
Here is the code for anyone else who finds this post.
Javascript:
$.ajax({
type: 'post',
url: 'my-url-path',
data: {'location': myLocationParam},
dataType: 'html',
timeout: 50000
}).done(function(locationResponse) {
if (locationResponse !== 'fail')
{
// Handle success.
console.log('----------------- LOCATION OUTPUT -----------------');
console.log(locationResponse);
console.log('---------------------------------------------------');
}
else // No location data.
{
// Handle no data.
}
}).fail(function(error) {
// Handle fail.
});
PHP:
if ( isset($_POST['location']) )
{
$location = $_POST['location'];
$resource = $modx->getObject('modResource', array('pagetitle' => $location, 'parent' => 1)); // Limit search to resource ID 1
if ( $resource )
{
$fields = $resource->toArray(); // An arrry of page fields (pagetitle, longtitle etc).
$resoruceID = $fields['id'];
$headline = $fields['pagetitle'];
$output = $modx->runsnippet('getResources', array(
'parents' => $resoruceID ,
'tpl' => 'myTemplateTpl',
'showHidden' => 1,
'default' => '<p>No data found for this location.</p>'
));
}
else
{
$output = '<p>No results found!</p>';
}
}
else // No data to make getResources call.
{
$output = 'fail';
}
echo $output;
Chunk (myTemplateTpl) - (for example purpose):
<h1>[[+longtitle]]</h1>
[[+introtext]]