We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53432
    • 46 Posts
    When I link to a resource that’s in another context, should I expect the link to use that context’s subdomain?

    For example: if I edit a resource in my context “foo” (which is not the default context), and my link code is this:
    [[~42? &scheme=`full`]]


    …Where “42” is a resource in the default context.

    I will get a link that looks like this:
    http://foo.example.com/resource-in-default-context.html


    However I would expect it to look like this:
    http://www.example.com/resource-in-default-context.html


    Am I missing something?

    I am running ModX 2.7.1 and using the ContextRouter 1.2.0 on Linux/Apache/PHP/MySQL server.
      • 3749
      • 24,544 Posts
      Be sure that the base href tag in each template is called uncached (with the exclamation point):

      <base href="[[!++site_url]]" />


      Also, make sure that each context has these settings and they are set appropriately:

      base_url
      http_host
      site_url


      It that doesn't do it I would suspect that when the parser handles a link tag, it uses the value of the "base href" tag on the current page's template rather than consulting the context of the resource being linked to.

      Someone more familiar with ContextRouter can probably give you a better answer.

      Worst-case, a fairly simple custom snippet could take the place of those link tags and build the URL you want based on the target resource's context_key and a call to the context's makeUrl() method.

      You might also want to take a look a XRouting.
        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