We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41400
    • 11 Posts
    Hi,
    another thing context-related - maybe someone has a hint for me? Please, it drives me crazy! ;-)

    I have several contexts and I'm routing with GatewayManager (but also tried ContextRouter for my problem).

    So domain A.com routes to context A, B.com -> B, and so on.
    Then I have the default web conntext which I want to use for 'global' resources, that more than one context can refer to.

    For example, I have a resource in web-context, that shall be used as start-page (site_start) for each context. But I can't just link the domains to web-context, because the page grabs some information from the contexts, so it looks different in different contexts.

    Unfortunately, this seems do be impossible, as I get a 404 for each context, linking it's site_start to an other context.

    I have allow_forward_across_contexts set and for a custom 404-page pulling infos from the respective context (but sitting just once in web) this works like I would like it to work for site_start...

    Anyone an idea?

    Tried it with Revo 2.2.14 on a fresh installation (took me time to dig to the cause... :-/ )

    Thanks in advance!

    This question has been answered by markh. See the first response.

      • 14214
      • 299 Posts
      Have you tried a symlink? Place one in every context pointing at the desired homepage.
        • 41400
        • 11 Posts
        thank you for this idea - I should have mentioned, that I tried this one.
        It actually works but my intention was, to not having to have a resource in every context - avoidance of redundancy...
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          I don't think that's possible; when you route to a context you are telling MODX to look for the resource there. If the resource doesn't exist there, it returns a 404.

          You could try a custom routing plugin where you hardcode a list of aliases/requests that need to be served from a separate context. For example /site/foo.html routes to the web context with a base_url of /site/ so it serves foo.html from the web context route.

          That'll get a bit complex - and depends on that hardcoded list - but might be the best way to do it without any sort of redundancy like symlinks.

          Another option would be hooking into OnPageNotFound, again checking a list of aliases/requests, and using $modx->sendForward there. That should work as well, but because OnPageNotFound triggers after it searched the site for the resource, that's slower than hooking into OnHandleRequest and taking a shortcut to the right context.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 41400
            • 11 Posts
            thanks - even for that bad news. ;-)

            actually, i saw the contexts more like a container with a new layer of settings-inheritance... and as the resource-ids are globally unique, i don't get the point why anyone should have made up this restriction intentionally... ok, well, to separate contexts, but for that there is the allow_forward_across_contexts-setting, i thought... and with this on, it works for a 404-page from a different context! (so routed to context foo and served 404 from context web)
              • 41400
              • 11 Posts
              hmm... thinking about your mentioned hooks... for example hooking in OnPageNotFound and looking for the id that wasn't found... am i right, i had to switch to that resource's context to be able to serve it? then i don't get the way, allow_forward_across_contexts works...
              and actually, switching contexts isn't possible for my problem, as i need the info from the contexts in my resource.
              (i mentioned the 404 above - with allow_forward_across_contexts on, a custom 404 will be displayed in any context and will pull settings from that respective context, even if it lays somewhere else... so basically it works in this case... but i don't want to rely on 404s... ;-D )
              • discuss.answer
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                allow_forward_across_contexts has to do with the $modx->sendForward method I mentioned. It doesn't mean all of a sudden contexts can virtually be anywhere all of a sudden, it just means you can use sendForward across contexts wink

                Contexts are more than just containers for setting inheritance, they can be completely different and unique sites that have nothing to do with each other. Say you have a corporate site with an /about page as a context, and a webshop for a different client in a different context. You wouldn't want /about on the shop to automatically go to the /about page of the corporate site - that's why they're separate.

                Re-reading your post, this bit is actually impossible:
                For example, I have a resource in web-context, that shall be used as start-page (site_start) for each context. But I can't just link the domains to web-context, because the page grabs some information from the contexts, so it looks different in different contexts.
                .. unless you use a symlink. That's what symlinks are for; keeping the content synced but possibly being rendered differently as it's in a different context.

                The method I described earlier with $modx->sendForward will do basically an under the hood redirect, so they will look exactly the same and will not be rendered differently because of the different context.
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 41400
                  • 11 Posts
                  Mark, thank you for this clarification about contexts - it does make sense this way. ;-)

                  Digging deeper to the forums, I found a thread from 2012, describing a cross-context-resource... maybe I can use some pieces from this plugin to build a workaround - I didn't tried it yet... we'll see, when there is some free time... ;-)