On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hey, hello,

    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
    • I had this problem also - I couldn’t find the context key anywhere.

      What I did in the end was to get the current resource and retrieve it’s context_key property.
        Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

        modx Revolution 2.2.6
        Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

        Content-Managed Websites Built on MODX
      • $modx->context->key
        

        return the correct value !
          Low
        • Quote from: low at Oct 29, 2010, 11:33 AM

          $modx->context->key
          

          return the correct value !

          Cool! Thanks for sharing smiley
            Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

            modx Revolution 2.2.6
            Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

            Content-Managed Websites Built on MODX
          • 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;
            • Great Henk. That's exactly what i needed!

              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;