<![CDATA[ [SOLVED] Return the current context key - My Forums]]> https://forums.modx.com/thread/?thread=30357 <![CDATA[Re: [SOLVED] Return the current context key]]> https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-501526
Quote from: raadhuis at Apr 29, 2014, 09:54 AM
And for the people who want to retrieve the current context by a given ID I created the following simple snippet with Pandy06269's tip.

<!--?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;
]]>
jorgenh Jun 26, 2014, 08:11 AM https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-501526
<![CDATA[Re: [SOLVED] Return the current context key]]> https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-496401
<?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;
]]>
raadhuis Apr 29, 2014, 04:54 AM https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-496401
<![CDATA[Re: [SOLVED] Return the current context key]]> https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164549 Quote from: low at Oct 29, 2010, 11:33 AM

$modx->context->key

return the correct value !

Cool! Thanks for sharing smiley]]>
Pandy06269 Oct 29, 2010, 07:51 AM https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164549
<![CDATA[Re: Return the current context key]]> https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164548
$modx->context->key

return the correct value !]]>
low Oct 29, 2010, 06:33 AM https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164548
<![CDATA[Re: Return the current context key]]> https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164547
What I did in the end was to get the current resource and retrieve it’s context_key property.]]>
Pandy06269 Oct 29, 2010, 04:38 AM https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164547
<![CDATA[ [SOLVED] Return the current context key]]> https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164546
Well, I want to knows: how to return the current context key, In the API doc, no function exist for it (or I mistake ?)

Low]]>
low Oct 29, 2010, 04:21 AM https://forums.modx.com/thread/30357/solved-return-the-current-context-key#dis-post-164546