We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22098
    • 218 Posts
    hello,

    after having installed 2.0.0 alpha3 i am wondering how i actually can use the contexts? I have added a new context, and it shows up in the resources, and i can add documents to it. But what now? I was assuming i could use contexts for multilanguage sites, or managing multiple sites from within one manager? Any hints/tips how i can test this?

    Olaf
      • 24719
      • 194 Posts
      have you seen this?

      http://svn.modxcms.com/docs/display/~splittingred/2008/07/10/Creating+Custom+Manager+Pages+for+a+3rd+Party+Component%2C+Pt.+I

      it’s got some good info for getting you up and running with contexts.
        • 22098
        • 218 Posts
        Quote from: redman at Aug 15, 2008, 08:00 AM

        have you seen this?

        http://svn.modxcms.com/docs/display/~splittingred/2008/07/10/Creating+Custom+Manager+Pages+for+a+3rd+Party+Component%2C+Pt.+I

        it’s got some good info for getting you up and running with contexts.
        thanks for the link. I don’t think it was what i was looking for though. I was assuming that contexts where an easy way to create multiple sites that could be managed from within the same manager, but still have their own unique configs etc.?

        Olaf
          • 22303 MODX Staff
          • 10,725 Posts
          First, you’ll want to get the latest, as I made some significant improvements to context switching and cross-context URL generation in the core this week.

          But let’s start with an example. Here is a plugin I’m using to test a single configuration that is serving two domains based on the URL used to access the site:
          <?php
          switch ($modx->config['http_host']) {
              case 'domain2.tld:80':
              case 'domain2.tld':
                  // if the http_host is of a specific domain, switch the context
                  $modx->switchContext('domain2');
                  break;
              default:
                  // by default, don't do anything
                  break;
          }
          ?>

          So to test on my local machine, I can use localhost for web (the default context) and 127.0.0.1 to switch to my test context:
          <?php
          switch ($modx->config['http_host']) {
              case '127.0.0.1:80':
              case '127.0.0.1':
                  // if the http_host is of a specific domain, switch the context
                  $modx->switchContext('test');
                  break;
              default:
                  // by default, don't do anything
                  break;
          }
          ?>

          You’ll want to specifically set context configuration settings in each context so URLs are generated properly from other contexts, especially the http_host and site_url settings, though you can override many others.
            • 22098
            • 218 Posts
            Quote from: OpenGeek at Aug 29, 2008, 09:14 AM

            First, you’ll want to get the latest, as I made some significant improvements to context switching and cross-context URL generation in the core this week.

            But let’s start with an example. Here is a plugin I’m using to test a single configuration that is serving two domains based on the URL used to access the site:
            <?php
            switch ($modx->config['http_host']) {
                case 'domain2.tld:80':
                case 'domain2.tld':
                    // if the http_host is of a specific domain, switch the context
                    $modx->switchContext('domain2');
                    break;
                default:
                    // by default, don't do anything
                    break;
            }
            ?>

            So to test on my local machine, I can use localhost for web (the default context) and 127.0.0.1 to switch to my test context:
            <?php
            switch ($modx->config['http_host']) {
                case '127.0.0.1:80':
                case '127.0.0.1':
                    // if the http_host is of a specific domain, switch the context
                    $modx->switchContext('test');
                    break;
                default:
                    // by default, don't do anything
                    break;
            }
            ?>

            You’ll want to specifically set context configuration settings in each context so URLs are generated properly from other contexts, especially the http_host and site_url settings, though you can override many others.

            cheers!