We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1331
    • 129 Posts
    I have successfully pulled in different data chunks from other contexts in my install. But is there a way to either generate a link directly to another context’s homepage and/or generate a list of all existing contexts?
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: ambaxter at Apr 17, 2010, 01:04 PM

      I have successfully pulled in different data chunks from other contexts in my install. But is there a way to either generate a link directly to another context’s homepage and/or generate a list of all existing contexts?
      You could simply use link tags with the actual id of each contexts site_start, use weblinks to create navigation to other contexts from each context, or use something like this (untested):
      <?php
      $output = array();
      $contexts = $modx->getCollectionGraph('modContext', '{"ContextSettings":{}}', array(
          'modContext.key:!=' => $modx->context->get('key')
          ,'modContext.key:!=' => 'mgr'
          ,'ContextSettings.key' => 'site_start'
      ));
      foreach ($contexts as $context) {
          $data = $context->toArray();
          if (!empty($context->ContextSettings)) {
              $siteStart = reset($context->ContextSettings);
              $data = array_merge($data, array('site_start' => $siteStart->get('value')));
          }
          $output[] = $modx->getChunk($tpl, $data);
      }
      return implode("\n", $output);
      ?>

      and use a chunk like this for the &tpl:
      <li><a href="[[~[[+site_start]]]]" title="[[+description]]" rel="external">[[+key]]</a></li>


      I’m also considering adding a new feature to settings placeholders that would allow you to specify the context, e.g.
      [[++site_start? &context=`contextA`]]

      or a similar mechanism for convenience.
        • 1331
        • 129 Posts
        I’m barely getting back to this experiment.

        The snippet code you posted, plus the TPL work perfectly! This is sweet.
          • 1331
          • 129 Posts
          If this is something worth exploring further, the next step would be to somehow hide certain contexts based on a setting.