We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9907
    • 4 Posts
    Spent a long time on this last night and I figure it’s time to call for some assistance. I know everyone says this, but it sure looks like it should work. I’m trying to provide for two different calls to Wayfinder: if the current document is at level 1, then call Wayfinder with startId set to [*id*], or if the current document is at level 2, then set startId to [*parent*]. I start with a snippet in the template:

    [[hasChildren? &noChildChunk=`noKidsSubMenu` &childChunk=`foundKidsSubMenu`]]


    I’m using this snippet from Taff. If the document has children, then it inserts the chunk that displays a submenu. Here is the foundKidsSubMenu:

    <div id="subnav-wrapper">
    	<div id="subnav-wrapper-2">
    		<div class="center-wrapper">
    			<div id="subnav">
    				[[Wayfinder? startId=`[!wfStartid!]` &level=`2` &outerClass=`tabbed` &hereClass=`current_page_item`]]
    				<div class="clearer"> </div>
    			</div>
    		</div>
    	</div>
    </div>
    


    The main line is the Wayfinder call. For the startId, I use the snippet wfStartid, which looks liks this:

    <?php
    $parent = $modx->documentObject['parent'];
    $id = $modx->documentObject['id'];
    if($parent == 0) return $id;
    return $parent;
    ?>
    


    If the document’s parent is 0, then return the document ID, otherwise return its parent’s ID. Everything seems to work separately, but not all together. The problem seems to be in using the snippet as the startId argument to Wayfinder. I can put [!wfStartid!] by itself in the chunk and it displays the proper values. I can put a number in for the startId and it works fine. The two just aren’t working together. Am I just nesting too much? A snippet as a snippet argument in a chunk in a snippet? I’m sure there are other ways to do this and it’s almost guaranteed there are better ways to do it, but I’m just learning MODx and would appreciate a gentle nudge. Thanks.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Consider the way snippets are processed. Normal (cached) snippet tags are processed as they are encountered. So your outer Wayfinder snippet is being processed, but the value of &startId is still [!wfStartId!], which of course does Wayfinder no good at all.

      An uncached snippet is not processed right away when it is first encountered; its tags are changed from [!...!] to [[...]], and it is skipped until later in the page generating process. So if your outer snippet call is uncached, and the innner snippet call is cached, then the inner snippet will be processed right away, and when the outer snippet is finally processed later on, its parameter will have the proper value.
      [!Wayfinder? startId=`[[wfStartid]]` &level=`2` &outerClass=`tabbed` &hereClass=`current_page_item`!]


        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
        • 9907
        • 4 Posts
        sottwell: Many thanks for the insight and a solution that works. I’ve read through some of that before and it’s still in the sinking in stage. In fact, I spent a fair amount of time at your web site going through your incredibly helpful tutorials. Looks like I’m going to have to read them a couple more times. Thanks for the time you spend doing that and helping us newbies along the way. It’s very much appreciated.
          • 3749
          • 24,544 Posts
          Quote from: sottwell at Nov 17, 2009, 11:22 AM

          Consider the way snippets are processed. Normal (cached) snippet tags are processed as they are encountered. So your outer Wayfinder snippet is being processed, but the value of &startId is still [!wfStartId!], which of course does Wayfinder no good at all.

          An uncached snippet is not processed right away when it is first encountered; its tags are changed from [!...!] to [[...]], and it is skipped until later in the page generating process. So if your outer snippet call is uncached, and the innner snippet call is cached, then the inner snippet will be processed right away, and when the outer snippet is finally processed later on, its parameter will have the proper value.
          [!Wayfinder? startId=`[[wfStartid]]` &level=`2` &outerClass=`tabbed` &hereClass=`current_page_item`!]


          Is this still the case in Revolution?
            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