We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51675
    • 6 Posts
    Hello All! I'm hoping someone might be able to give me some help! I'm new to modx I'm afraid...

    I'm working on an existing multi language website (modx 2.3.3 / babel 2.2.5). The separate language versions are set up in separate contexts, as I believe is usual with Babel.

    There's a plugin called "Gateway" attached to the OnHandleRequest system event that is doing various things including some IP-to-geo.

    But the site as a whole doesn't have translations for *every* page.

    I need to check whether translations exist in the "Gateway" plugin, before (if necessary) switching context.

    So... maybe I'm going about this the wrong way... but I thought I'd use runSnippet to run the BabelLinks snippet from "Gateway" and thereby work out which translations were available.

    The problem is that $modx->resource is still undefined at this point so I can't pass a resourceId parameter to BabelLinks.

    I've tried using findResource on $_REQUEST['q'] but I can't get this working - maybe when modx does it $_REQUEST['q'] gets cleaned up somehow?

    Is there a better way to approach this?

    With thanks for any help!

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

    [ed. note: nightand last edited this post 10 years, 9 months ago.]
      • 3749
      • 24,544 Posts
      I don't know anything about Babel, but you can set $modx->resource yourself if you have a default page in mind and that would work for you.

      $docId = 12; // ID of default page
      $modx->resource =& $modx->getObject('modResource', $docId);
      


      If the page you want is in the $_GET array, you should be able to pull it out and rewrite the code above to use it.

      This might give you useful information in the MODX Error Log:

      $msg = print_r($_GET, true);
      $modx->log(modX::LOG_LEVEL_ERROR, $msg);
      
        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
      • discuss.answer
        • 51675
        • 6 Posts
        What I forgot to explain was that I don't have the resource id in the Gateway plugin because we're using friendly urls.

        Rather than $_GET['q'] being the resource id (as I believe would be usual when NOT using friendly urls), $_GET['q'] is the friendly url.

        This is why I was using the "findResource" method to find the resource id associated with the friendly url. But it doesn't always seem to work and I'm wondering if it's because I have to manually clean up things like the presence (or not) of trailing slashes in $_GET['q'].

          • 3749
          • 24,544 Posts
          Possibly. What does the code I posted above put in the error log?
            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
            • 51675
            • 6 Posts
            Actually I think I have it working now. I'm basically doing this:

            if (isset($_REQUEST['q']) && $_REQUEST['q'] != '') {
                $alias = $_REQUEST['q'];
                $resource_id = $modx->findResource($alias); 
                if (!is_numeric($resource_id)) $resource_id = $modx->findResource($alias . '/'); 
                if (is_numeric($resource_id)) {
                    //got resource id so can now use BabelLinks snippet (slightly modified) to check for translations
                }
            }
            


            So if I fail to find the resource id from the alias without a trailing slash, I just slap one on the end and try again...

            But thanks for your help, though, and not just here - I already recognise your name from various other modx postings!
              • 3749
              • 24,544 Posts
              I'm glad you got it sorted. smiley
                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