We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37514
    • 178 Posts
    Simple question! I have a chunk which needs to display [[++site_url]] of a specific context (say 'web') no matter where it is placed, including in other contexts with different [[++site_url]]s.

    How do I do this?

    Thanks!
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      First thing that comes to mind is a snippet along these lines..

      <?php
      $context = $modx->getObject('modContext', $ctx);
      if ($context) {
        return $context->getOption('site_url');
      }
      return 'ctx not found';


      used as
      [[getSiteUrl? &ctx=`web`]]
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 37514
        • 178 Posts
        Thanks Mark - tried that - for some reason it is returning the site_url of the context the snippet is in, unless &ctx is set to something that doesn't exist, in which case, it fails and returns 'ctx not found' as you'd expect smiley

        I'll see if I can get someone to take a look later smiley
          • 3749
          • 24,544 Posts
          I think this would do it:

          [[getContextSetting? &context=`someContext`, $setting=`site_start`]]

          <?php
          /* getContextSetting snippet */
          
          $ctx = $modx->getOption('context', $scriptProperties, null);
          $setting = $modx->getOption('setting', $scriptProperties, null);
          
          if ($ctx == null) {
             return 'No Context set';
          } elseif ($setting === null) {
             return 'No Setting set';
          } else {
              $csObj = $modx->getObject('modContextSetting', 
                  array('context_key' => $ctx, 
                        'key' => $setting
                       )
              );
          }
          
          if ($csObj) {
             return $csObj->get('value');
          } else {
            return 'Context Setting not found';
          }
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 37514
            • 178 Posts
            Thanks Bob - works great!