We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35644
    • 3 Posts
    So I’m out of ideas. We have a header that is using a Wayfinder snippet for the navigation. Works beautifully on the site. But Wayfinder isn’t processed and cached at the save point, it’s processed at runtime.
    That’s all fine, but we have an external site that we want to use that same header on. I thought, okay, no big deal. I’ll just process the modChunk object for the header and output it to an html file. This works for everything but Wayfinder. I can’t figure out what I need to give Wayfinder.

    So here’s my Header Export Plugin:
    $eventName = $modx->event->name;
    if ($eventName == 'OnChunkFormSave') {
        if (isset($modx->event->params['chunk']) && $modx->event->params['chunk']->name == 'header') {
            //hack to force resource to have a value
            $modx->resource = $modx->getObject('modResource', array('alias'=>'blog'));
            $output = $modx->parseChunk('header', array());
            file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/header.html', $output);
        }
    }
    


    My header has this Wayfinder snippet:
    <div id="nav">
        [[Wayfinder? &startId=`0` &level=`3` &parentRowTpl=`cssplay_revParentRow` &cssTpl=`cssplay_ultdrop` &excludeDocs=``]]
    </div>
    


    Admittedly, I’m not really an expert in modX. I’m comfortable and generally know my way around, but I can’t figure this one out.
    This project is php 5.3, modx 2.0.5 (I can usually translate any 2.1/2.2 code down, so whatever you can suggest is cool.)

    Any thoughts froms yous guys?
      • 35644
      • 3 Posts
      Note to all who may have looked. If you’re running the latest WayFinder you just need the following:

      <div id="nav">
          [[Wayfinder? &contexts=`web` &startId=`0` &level=`3` &parentRowTpl=`cssplay_revParentRow` &cssTpl=`cssplay_ultdrop` &excludeDocs=``]]
      </div>
      


      The problem was that the version of WayFinder I am running didn’t automatically run $modx->switchContext(). The code above forces the context.

      New problem, though: Template Variables aren’t filled. I’m still sorting that out.
        • 3749
        • 24,544 Posts
        Try using $chunk->process() instead of parseChunk(). I’m not sure it will make any difference, but it’s worth a try.
          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
          • 35644
          • 3 Posts
          Embarrassingly, this was user error. I misnamed a Chunk... rolleyes