We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17546
    • 75 Posts
    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
      • 22629
      • 194 Posts
      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
        • 17546
        • 75 Posts
        $modx->context->key
        

        return the correct value !
          Low
          • 22629
          • 194 Posts
          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
            • 40016
            • 32 Posts
            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;