We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43373
    • 3 Posts
    MODX Revo 2.2.13
    Apache 2.2
    Developing on Windows 7

    I have a chunk that contains a side menu system. The menu contains a variety of links to other pages. The chunk is called from the main template. This part is all easily done.

    The issue is that the site will have many sub-domains that will be in separate contexts but use the same basic pages to display information. Since the menu chunk has generated links, for example - [[~6]], that reference resource pages in the web context, those links will not generate properly from the other sub-domain context. All I end up with for the links are the base URL and any thing that was typed in after the first "/". For example... sub.main.com/whatever-was-typed

    I have tried Gateway Manager and ContextRouter but this does not seem to be what they are for. There has to be some way to do this, otherwise I would have to make a different chunk for every sub-domain - which makes something so simple ridiculously complicated.

    Any one know how to accomplish this?
      • 3749
      • 24,544 Posts
      That issue was supposed to be fixed back in Revo 2.2.9. Are you sure each context has a site_url and base_url context setting?

      If that's not it -- I'm guessing here, but the makeUrl() that does the real work is actually a method of the context object, so this snippet might do it (in place of each link tag):


      [[!GetUrl? &context=`web` &docId=`12`]]



      <?php
      
      /* GetUrl snippet */
      // $currentContext = $modx->context->get('key');
      $key = $modx->getOption('context', $scriptProperties, $modx->context->get('key'));
      //$modx->switchContext($key);
      $context = $modx->getObject('modContext', array('key' => $key));
      $context->prepare();
      $docId = $modx->getOption('docId', $scriptProperties, $modx->getOption('site_start'));
      $url = $context->makeUrl($docId, "", "full");
      // $modx->switchContext($currentContext);
      
      return $url;


      The call to $context->prepare() could have weird side effects. If it does, remove it and uncomment the three commented lines.
        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
        • 43373
        • 3 Posts
        Yes, site_url and http_host are set for both contexts.

        I have not tried your suggestion. I uninstalled the gateway component. Cleared all caches. Now the URLs are being created except for [[~1]] - which is the main start page which is contained in the web context.

        Here is what I have.

        Web context containing resource 1 and 2 (there are others, this is just for example)

        Sub-domain context contains symbolic link to resource 1 in the web context.

        The menu chunk contains [[~1]] and [[~2]]. The link for resource 2 is correct but the link for 1 is just the base URL and /whatever-is-typed. There are no differences in the settings for 1 & 2 - no security settings or anything.

        Also, FURLS are not working even though enabled.

        My htaccess has all subdomains pointing to the same folder.

        I have to leave but I will be looking into this more.