Last active
October 14, 2018 19:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Usage [[!contextKey]] | |
* */ | |
return $modx->context->key; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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