We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9102 ☆ A M B ☆
    • 318 Posts
    This is basically a repost of the question that arose in this thread:

    https://forums.modx.com/thread/74641/run-a-snippet-from-outside-modx#dis-post-424258

    This question arises from trying to run Wayfinder somewhere other than the normal front end of the site (externally, or from within the manager or something like that). Wayfinder uses $modx->resource and fails if it is not set, but we can't seem to find a way to set it. I've tried the following and they all fail:

    $modx->resource = $resource;
    $modx->resource = & $resource;
    $modx->set('resource', $resource);
    $modx->set('resource', &$resource);
    
      • 22303 MODX Staff
      • 10,725 Posts
      Should work fine assuming $resource is a valid modResource derivative (i.e. modDocument), though you likely need additional data for Wayfinder to work outside of a modX request cycle...

      <?php
          $modx->resource = $resource;
          $modx->resourceIdentifier = $resource->get('id');
      


      The rest completely depends on how you process the Resource.
        • 9102 ☆ A M B ☆
        • 318 Posts
        Thanks! I was missing the resourceIdentifier. Now I'm one step closer -- except that when I call Wayfinder in the mgr context, the output is empty, and if I switch contexts first, Wayfinder fails again.

        I'll play with it and see if I can figure out where it's failing now, but at least I'm making progress!


        Wait, strike that, it is working if I switch contexts, just not sending message back to the console.

        Whohoo!

        The console/context thing is problematic but I think I can get around it.

        Opengeek, you're a gentleman and a scholar.

        With any luck, I'll have a really fun extra for you to play with in a few days. I'm very excited about this one, it may solve the speed problem... [ed. note: esnyder last edited this post 14 years, 5 months ago.]