We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42841
    • 24 Posts
    Hi,

    A lot of the work I do is Facebook page tab apps - and one of the nitpicks about Facebook apps, is they're best when they're loaded from a single URL and never redirected/refreshed. This is because the signedRequest only gets posted once.

    I currently have an app that determines whether the user is from New Zealand or Australia, and redirects to /nz/ or /au/ accordingly. I then use FirstChildRedirect to grab the first published competition page.
    This works, but it isn't ideal.

    I have tried to return $modx->getResource(), but I just get an array dump (yes, I have set tpl and the other required properties)


    So, my question is - when I go to http://myurl.com/ - can I do the calculations on the backend and return whichever resource I like in place, without navigating/changing the URL/redirecting?

    Thanks,
    Ahren.

      • 34084 ☆ A M B ☆
      • 756 Posts
      You can take a look at the sendForward method, which allows you to forward a request to a different resource in Modx without requesting the URL.

      Cheers
        Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
        Visit CharlesMx.com for latest news and status updates.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You also might be able to use a plugin to change the resource ID to load in a single symlink resource. A symlink is a page that loads the content of a specified resource instead of having content of its own.

        Or you could load the desired content via AJAX.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 38290
          • 712 Posts
          What about having the linked to resource just be a symblink associated with the resource to pull data from?

          Did this for Sartori Cheese, even though these are separate pages, the shop one is just a symblink, so it has a different template but loads data from the other resource
          http://www.sartoricheese.com/products/reserve-cheese/black-pepper-bellavitano/
          http://www.sartoricheese.com/products/reserve-cheese/black-pepper-bellavitano/shop-black-pepper-bellavitano.html
            jpdevries
            • 42841
            • 24 Posts
            Thanks everyone for the replies.

            I think sendForward is what I was looking for! But I'll also explore symlinks in more detail as well.

            Cheers
            Ahren
              • 3749
              • 24,544 Posts
              Yes, sendForward() will pull the content of the other resource into the current resource without changing the URL or the template.

              getResources() should also work, but you have to use $modx->runSnippet() and provide the properties in a second argument. Something like this:


              $fields = array (
              
                 'tpl' => 'MyTpl',
                 'resources' => '12',
              
              }
              
              return $modx->runSnippet('getResources', $fields);


              You could also use getResourceField() the same way;
                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