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

    I’am trying to use the MODx API to get my MODx menu into an external PHP application.
    The snippet call in my MODx site is the following :
    [[Wayfinder?startId=`0` &outerTpl=`mh.OuterTpl` &innerTpl=`mh.InnerTpl` &rowTpl=`mh.RowTpl` &innerRowTpl=`mh.InnerRowTpl` &firstClass=`first` &hereClass=``]]
    


    The code I tried in my external application :
    <?php
     
    include_once(realpath("../modxapi.php"));
    $modx = new MODxAPI();
    $modx->connect();
    $modx->getSettings();
    
    $chunk1 = $modx->getChunk('mh.OuterTpl');
    $chunk2 = $modx->getChunk('mh.InnerTpl');
    $chunk3 = $modx->getChunk('mh.RowTpl');
    $chunk4 = $modx->getChunk('mh.InnerRowTpl');
     
    $modxmenu = $modx->runSnippet('Wayfinder', array('startId' => '0', 'outerTpl' => $chunk1, 'innerTpl' => $chunk2, 'rowTpl' => $chunk3, 'innerRowTpl' => $chunk4, 'firstClass' => 'first', 'hereClass' => ''));
    
    ?>
    


    The menu is generated, but without taking care of the different chunk mh.OuterTpl, mh.InnerTpl, etc.
    Does anyone know what’s wrong with that code ?

      R
      • 11975
      • 2,542 Posts
      Hi cecile,

      Did you try to remove the getChunk part of your code.

      In my opinion WF expects chunk name as param and not their content.

      :-)

      <?php
       
      include_once(realpath("../modxapi.php"));
      $modx = new MODxAPI();
      $modx->connect();
      $modx->getSettings();
      
      $chunk1 = 'mh.OuterTpl';
      $chunk2 = 'mh.InnerTpl';
      $chunk3 = 'mh.RowTpl';
      $chunk4 = 'mh.InnerRowTpl';
       
      $modxmenu = $modx->runSnippet('Wayfinder', array('startId' => '0', 'outerTpl' => $chunk1, 'innerTpl' => $chunk2, 'rowTpl' => $chunk3, 'innerRowTpl' => $chunk4, 'firstClass' => 'first', 'hereClass' => ''));
      
      ?>
      
      
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 18397
        • 3,250 Posts
        Wayfinder expects a chunk name for its templates, not actual code. Thus, just substitute $chunk1 with ’mh.OuterTpl’ and so on and it should work.
          • 1186
          • 202 Posts
          Oh great, it works fine indeed ! Many thanks for your help, Heliotrope and Mark, and for your ultra reactivity !
            R