Skip to content

Instantly share code, notes, and snippets.

@pepebe
Last active October 14, 2018 19:04
Show Gist options
  • Save pepebe/47a0b91fe1e55959f155d3764a56ebd2 to your computer and use it in GitHub Desktop.
Save pepebe/47a0b91fe1e55959f155d3764a56ebd2 to your computer and use it in GitHub Desktop.
Retrieve Context Key inside snippets. See https://forums.modx.com/thread/30357/solved-return-the-current-context-key for more details.
<?php
/*
* Usage [[!contextKey]]
* */
return $modx->context->key;
<?php
/*
* Usage [[!getContext? &id=``]]
*/
//retrieve ID or use current resource
$id = (!empty($id) ? $id : $modx->resource->get('id'));
//retrieve context
$page = $modx->getObject('modResource', $id);
$output = $page->get('context_key');
//return output
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment