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

    i’m having a hard time here figuring out the exact steps. I can clearly feel that i lack knowledge at certain topics (mod_rewrite, regex), but i’m eager to learn.

    What i want to achieve:
    Having several document trees, seperated by contexts: one context for english, one context for german, one for french.
    The documentation i found "translates" context into subdomains, like en.domain.com, fr.domain.com.

    But for my site i wish to keep a folder-like structure: domain.com/en, domain.com/fr

    I read this piece of documentation and learned about the settings one can override for each context.

    I read this piece of documentation and learned about a needed call somewhere in the code (may it be through a plugin or a seperate index.php)

    $modx->initialize('aContextNameOfYourChoice'); 


    Now the things that kept me from succeeding:

    way2go 1: switch-plugin
    With a folder-like structure the http-host-parameter stays always the same, right? so i can’t switch the contexts depending on that. is there any parameter that could do the same for subfolders?
    and what FURL-settings should there be to display contexts as subfolders? with friendly_url_prefix?

    way2go: subfolders with duplicated and modified index.php
    when creating a "physical" /fr/ subfolder, i have the problem of not knowing how exactly to change the rewrite rule. with this method i succeded to display the fr-contexts startpage, but the subpages got messed up by FURLs and wrong rewrite-settings.


    I know i demanded from the community the last days, but if i get this setup up and running, i’m totally willing to give sth back in form of a step-by-step tutorial for the modx-beginners to follow after me.. so bare with me smiley
    thanks, niklas
    • FWIW, I do not know that Contexts have been used in this way yet. I am running some experiments with this today and will report back when I figure out how/if it can work. If it doesn’t work, I will be entering a bug report and getting it fixed ASAP.
      • I successfully got it working using the plugin approach. The plugin code is below, along with the Context Settings for the subfolder Context I setup...
        <?php
        $pieces = explode('/', trim($_REQUEST[$modx->getOption('request_param_alias', null, 'q')], '/'), 2);
        if (count($pieces) > 0) {
            switch ($pieces[0]) {
                case 'web2':
                    if (isset($pieces[1])) {
                        $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = $pieces[1];
                    } else {
                        $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = '';
                    }
                    $modx->switchContext('web2');
                    break;
                default:
                    break;
            }
        }
        ?>

        [table]
        [tr]
        [td]setting key[/td][td]setting value[/td]
        [td]base_url[/td][td]{base_url}web2/[/td]
        [td]site_url[/td][td]{site_url}web2/[/td]
        [td]site_start[/td][td]11[/td]
        [td]error_page[/td][td]12[/td]
        [td]unauthorized_page[/td][td]13[/td]
        [/tr]
        [/table]
        This would only work when using friendly URLs btw.
        • Wow, thanks a lot, opengeek. you’ve been a great help for me learning modx.
          Your approach also works over here, great smiley

          i also understand the approach of the script, you ask for the first bit of the alias string and switch case according to that.

          just two little questions to fully grasp it:

          what exactly did you do here:
          Quote from: OpenGeek at Jul 08, 2010, 07:21 PM

                      if (isset($pieces[1])) {
                          $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = $pieces[1];
                      } else {
                          $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = '';
                      }

          re-assigning the parameter-alias? but why?

          secondly, is there a documentation, where do find a list of parameters i could use in plugins and snippets? as a beginner to modx i would have never found the possibility to ask for "request_param_alias"...

          again, thanks a lot!
          • nklsf:

            $modx->getOption just searches for a system setting. So, you can reference any System Setting via $modx->getOption in your plugins/snippets/etc. request_param_alias is a System Setting, so opengeek just used that there.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • ah, i see.

              so

              $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = $pieces[1];


              does nothing else, as to rewrite the alias-string without the /de/ into the setting, because, that is already part of the contextsettings base_url and site_url, right?
              • Quote from: nklsf at Jul 13, 2010, 03:50 PM

                $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = $pieces[1];


                does nothing else, as to rewrite the alias-string without the /de/ into the setting, because, that is already part of the contextsettings base_url and site_url, right?
                Correct. The request_param_alias allows you to configure the REQUEST parameter that is used to identify a page request by alias (IOW when using friendly_urls). In Evo, this was hardcoded to q, which is the default.
                • again, thanks!
                  everything’s clear now cool
                  • OpenGeek thank you for simple but working solution. I just want to report it works like charm.
                    It is good example of how to work with Contexts and it definitely shall be included in rtfm

                    http://rtfm.modx.com/display/revolution20/Contexts
                    • Quote from: OpenGeek at Jul 08, 2010, 07:21 PM

                      I successfully got it working using the plugin approach. The plugin code is below, along with the Context Settings for the subfolder Context I setup...
                      <?php
                      $pieces = explode('/', trim($_REQUEST[$modx->getOption('request_param_alias', null, 'q')], '/'), 2);
                      if (count($pieces) > 0) {
                          switch ($pieces[0]) {
                              case 'web2':
                                  if (isset($pieces[1])) {
                                      $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = $pieces[1];
                                  } else {
                                      $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = '';
                                  }
                                  $modx->switchContext('web2');
                                  break;
                              default:
                                  break;
                          }
                      }
                      ?>

                      [table]
                      [tr]
                      [td]setting key[/td][td]setting value[/td]
                      [td]base_url[/td][td]{base_url}web2/[/td]
                      [td]site_url[/td][td]{site_url}web2/[/td]
                      [td]site_start[/td][td]11[/td]
                      [td]error_page[/td][td]12[/td]
                      [td]unauthorized_page[/td][td]13[/td]
                      [/tr]
                      [/table]
                      This would only work when using friendly URLs btw.

                      hello
                      the approach worked fine untill i have to use makeUrl for php need

                      so when i want to make a url with programmatically
                      $this->modx->makeurl($this->modx->resource->get(’id’),’web2’,’module=article&oid=24’);
                      is creating url for the web context only not web2 context
                      expected mysite/web2/test.htm?module=article&oid=24
                      but creating mysite/test.htm?module=article&oid=24

                      so how to make it work with makeUrl?