We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42925
    • 4 Posts
    I can't seem to get a snippet to load properly in a secondary context. I have my primary website at domain1.com and the secondary at sub.domain2.com. I used the instructions here to setup the subdomain: http://rtfm.modx.com/revolution/2.x/administering-your-site/contexts/creating-a-subdomain-from-a-folder-using-virtual-hosts. This part worked without a problem. The page, sub-pages with friendly urls, chunks, and so on all load fine. Here are the context settings:

    The anonymous user group has load privileges on the context (this was done by default when the context was added). I did add a resource group on domain1.com to make a members only area. However, it looks like by default anonymous users can access any pages without a resource group applied (the non-member areas).

    The test snippet makes a simple timestamp:
    <?php
    return date('Y-m-d h:m:s');


    If I use this snipped in the primary context, no problem. If I try it in the secondary site, it doesn't work. And here is the strange part. After it loads successfully in the primary context, then it can load in the secondary context. Once it loads successfully in the primary context, the timestamp updates each time I refresh the page on domain2. If I clear the cache, it doesn't work anymore until it loads successfully in the primary context again.

    I added a debug script to the snippet to see when it is triggering:

    $modx->setLogLevel(modX::LOG_LEVEL_DEBUG);
    $modx->log(modX::LOG_LEVEL_DEBUG, 'test snippet fired');


    When I run this in the web context, the message appears in the error log as anticipated. However, when I run it on domain2, the timestamp updates, but there is no record in the log. It looks like the snippet is blocked somehow, so it pulls the php from the cache.

    I am running modx 2.2.13 SDK. The security settings are the default with the exception of adding a resource group for the members only area. It looks like this might be a permissions issue, but I can't seem to find anything that makes sense to change. I have cleared the cache, flushed permissions, and flushed all sessions to ensure the anonymous user is seen as having privileges to access the domain2 context. Any ideas?
      • 3749
      • 24,544 Posts
      What happens when you have the snippet tag uncached?

      [[!SnippetName]]


      Have you tried using another browser where you're not logged into the Manager?

      Are there any Element Category Access ACL entries that affect the snippet?

      What's the policy for the Context Access ACL entry for the second context?

      It's odd, because AFAIK, snippets are context-agnostic. They are not tied to a context in any way and should be equally available to run in any context unless there is an Element Category Access ACL entry or the snippet itself contains code to block access in a certain context.
        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
        • 42925
        • 4 Posts
        I have been trying it uncached. I tried it in another browser to ensure it was accessing the anonymous user group (not conflicting with the manager). There are no Element categories assigned.

        When I go to update the anonymous user group and go to the context access tab, I have:

        Context: Web | Min Role: Member - 9999 | Access Policy: Load Only
        Context: Web2 | Min Role: Member - 9999 | Access Policy: Load Only

        For testing purposes, I changed the access policy to administrator, but that didn't make a difference, so I set it back to "Load Only". Is there anywhere else I should look?
          • 3749
          • 24,544 Posts
          When you switched it to Administrator, did you flush both permissions and sessions before testing? If not, try that. Otherwise, you haven't really ruled out the access policy as a cause.
            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
            • 42925
            • 4 Posts
            I tested it again as you said, flushing permissions and sessions, and in a separate browser. Still doesn't work.

            I have both sites on the same server, but they are on different cpanel accounts. I am not sure if that makes a difference.
              • 42925
              • 4 Posts
              It looks like I might need to use the "add-on domain" function within cpanel rather than using a separate account in WHM. The index.php file in sub.domain2.com system is able to request PHP files and execute database requests from the domain1 cpanel account. All other functionality works between Cpanel accounts except snippets.

              In my particular case, I will not be able to use the "add-on domain" so that they are all in the same cpanel account. When I do try to use the add-on domain feature in cpanel, it doesn't allow me to because domain2.com already exists as an account on the server. domain2.com is running a different CMS platform (from before I had this client). As a result, I am creating sub.domain2.com to add new functionality, but I wanted to share with data at domain1.com.

              Could this be a security feature in Modx to prevent cross-site attacks, since all other functionality works? Or maybe there is a server setting that could be changed? My only alternative at the moment would be to have separate installs and not share the data. Any other ideas?
                • 3749
                • 24,544 Posts
                Quote from: bglick at Mar 08, 2014, 12:51 PM

                I have both sites on the same server, but they are on different cpanel accounts. I am not sure if that makes a difference.

                Maybe the second domain doesn't have access to the MODX database but does have access to the cache directory. Someone who has more experience with virtual hosts could probably be more help than I can.
                  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
                  • 49913
                  • 1 Posts
                  Hello glickDev,

                  I have the same problem on a multi-sites MODx Revo using Babel.
                  Did you find a solution?

                  Thanks in advance for your answer.