We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37393
    • 68 Posts
    Hi, how can i run a snippet outside the MODX core? I mean on "raw php pages" that are non-modx etc.
    I would like to use Wayfinder but also other snippets in my SMF forum template.

    Is this possible?

    MODX Rev 2.2.0
      IntoVPS - VPS hosting service with super-fast response.
      If MODx does not suit your needs then you have a lack of imagination.
      • 10076
      • 1,024 Posts
      I guess not no? I use SMF on a Evo site but never managed the integration. So in the end I just use the layout with a single static link back to the MODx page(s).
        • 33968
        • 863 Posts
        Totally possible:
        http://rtfm.modx.com/display/revolution20/Loading+MODx+Externally

        You'll end up with something like this:
        <?php
        require_once '/absolute/path/to/modx/config.core.php';
        require_once MODX_CORE_PATH.'model/modx/modx.class.php';
        $modx = new modX();
        $modx->initialize('web');
        $modx->getService('error','error.modError');
        
        // run Wayfinder (add your config params to the array)
        $wayfinder = $modx->runSnippet('Wayfinder', array('startId' => 0, 'level' => 1));
        
          • 10076
          • 1,024 Posts
          Good to know.
            • 29201
            • 239 Posts
            Is this possible in Evo?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I would put the snippet in a resource with no template then fetch that page in the external php code.

                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
                • 29201
                • 239 Posts
                Yes! Thx you yet again Susan!!!
                  • 36517
                  • 14 Posts
                  I've been trying to do this with Wayfinder, but it isn't working. It's failing by just failing and not processing anything else. I suspect what's happening is Wayfinder is trying to return a value that isn't set. I was trying to trace that through Wyafinder but it is veery difficult and time-consuming and I was wondering if anyone knew.

                  This is basically the ode (but I'm removed my attempt at tracing through Wayfinder).

                  <?php
                  	define('MODX_API_MODE',true);
                  	define('MODX_DOCUMENT_IDENTIFIER', 49);
                  	require_once '[PATH HERE]/config.core.php';
                      require_once MODX_CORE_PATH.'model/modx/modx.class.php';
                      $modx = new modX();
                      $modx->documentIdentifier = 49;
                  	$modx->initialize('web');
                  	$modx->getService('error', 'error.modError');
                  	
                  	$test = $modx->getObject('modResource',49);
                  	
                  	$modx->resource = $test;
                  	
                  	
                  	$output = $modx->runSnippet('Wayfinder',array( 'startId' => 1,'debug'=> true)); 
                          print $output; 
                  
                  


                  I can run chunks that don't have snippets that need whatever variable it is that isn't set. But I can't do Wayfinder. Is there a way to initialize modX as if I were a modX page in some more complate way than setting the document identifier or $modx->resource?
                    • 9102 ☆ A M B ☆
                    • 318 Posts
                    I'm having the same difficulty as kblair: I'm trying to run wayfinder from the manager instead of the front end, so modx->resource is not set, and I can't seem to set it. I tried the method above, and also tried:

                    $modx->set('resource', $test);
                    

                    And also
                    $modx->set('resource', &$test);
                    

                    Where $test is the actual resource object that I want wayfinder to use as the current resource. No dice, it just fails without throwing an error.
                      • 4172
                      • 5,888 Posts
                      you can try doing

                      $modx->resource = & $test;

                      ok, seems you have tested that
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!