We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22629
    • 194 Posts
    I’m trying out the Contexts to use one modx installation to manage multiple sites. I’ve tried a couple of different ways to switch contexts, but I’m finding that the resource tags are not being parsed in non-web contexts.

    Here’s my setup:

    - Installed modx 2.0.0-alpha-5 on (for example) www.site1.com - manager = www.site1.com/manager.
    - Set up www.site2.com to point to the same MODx install directory

    Context 1 (default: web)

    - Created a basic template which outputs the site name, page title in the TITLE tag, and the page’s content in the BODY.
    - Created a resource (page ID 1) which uses the above template
    - Preview the page - works fine

    Context 2 (new context: site2)

    - Created a new context called site2
    - Created a resource (page ID 2) which also uses the above template in the site2 context
    - Added the site_name and site_start (page ID 2) settings to context 2
    - Changed index.php to switch the context as follows:

    switch ($_SERVER['HTTP_HOST'])
    {
      case 'www.site2.com':
        $modx->initialize('site2');
        break;
    
      default:
        $modx->initialize('web');
        break;
    }


    Whenever I visit www.site2.com/?id=2 - modx parses the correct site name tag from the context, but doesn’t parse the document content tags - they don’t come out in the HTML output but don’t have any values in them (blank.)

    As this was an early recommendation by Jason for alpha-1, I had another look on the forums and came up with this: http://modxcms.com/forums/index.php/topic,29455.msg179824.html#msg179824

    So I tried this also:

    - Created a plugin called "Context Switcher" assigned to the OnHandleRequest event with the text in this article
    - Restored the changes made to index.php so the web context loads by default
    - Added the http_host (www.site2.com) and site_url (http://www.site2.com{base_url}) settings to the context

    It still makes no difference - no resource tags are being parsed in the site2 context (web context still works fine.)
    It’s switching the context OK because the site name changes, but it won’t parse the document tags in the non-web contexts. I’ve got a feeling it’s something ridiculously easy I’ve missed but I cannot see what!

    Any help would be appreciated.

    Thanks,

    Andy
      Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

      modx Revolution 2.2.6
      Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

      Content-Managed Websites Built on MODX
    • Check the actual response headers being generated and the core/cache/logs/error.log file for any problems. My test setup with localhost and 127.0.0.1 is working fine with the ContextSwitcher example.
        • 22629
        • 194 Posts
        Thanks for the reply Jason. Are you using the same version as the alpha-5 release or a newer one?
        I’ll have a look at the response headers when I get home this evening. I did examine the error.log file, but nothing was logged.

        Just another couple of questions that I came up with while doing these contexts:

        - is there a way to delete a context setting? I also cannot edit the settings - if I double click the grid to edit, it changes to the edit mode then very quickly (within milliseconds) changes back to the view mode. This is in Firefox.

        - also if I deleted a context, it didn’t delete the pages/resources assigned to the context

        Are these bugs you want filed in Jira?
          Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

          modx Revolution 2.2.6
          Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

          Content-Managed Websites Built on MODX
        • Also, make sure you have refreshed your cache.
            • 22629
            • 194 Posts
            I’ve found out what the issue is - my context was called "mnet_live" - when you moved a document into this context, the context_key column in the modx_site_content table is written as "mnet."

            I updated the record directly in the database, and it worked - however the document now doesn’t display in the manager!

            Also after this move has been done, a document in the "web" context has it’s context_key column set to "0" - so that then also fails to work!

            Thanks, Andy.
              Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

              modx Revolution 2.2.6
              Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

              Content-Managed Websites Built on MODX
            • Can you enter this as a Jira bug? The tree js uses _ to separate context from resource id in the nodes, so avoid the use of _ for now in contexts or it’s gonna break the tree view.
                • 22629
                • 194 Posts
                Jason, it looks as if the issue of it setting web context documents to 0 is a side-effect of naming a context with an underscore - I’ve created a context called "mnetLive" instead, and moving documents between contexts works fine.

                Raised as http://svn.modxcms.com/jira/browse/MODX-475.
                  Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

                  modx Revolution 2.2.6
                  Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

                  Content-Managed Websites Built on MODX