We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32645
    • 377 Posts
    In wayfinder you have to manually type the numbers of the docs you want to exclude, but lets say you’re wanting to build a sitemap and want the user/editor to have control over what pages to show/hide and you want to accomplish this via a "Show/Hide" checkbox template variable.

    How do you make Wayfinder exclude docs dependent on a template variable?
      • 22992
      • 1 Posts
      Any luck with this one? I have designed a solution based on the same way you are describing but I’m having problems implementing it. If you found a solution I’d would appreciate if you could share it.

      Thanks
        • 3186 ☆ A M B ☆
        • 279 Posts
        I know this topic is a little bit old, but I need a solution for the same problem, maybe someone knows howto fix it?

        This is my call (at least what I want to have)

        [[Wayfinder@TopMenu? &startId=`[[UltimateParent? &id=`[[*id]]`]]` &includeDocs=`[[getResources? &parents=`[[UltimateParent? &id=`[[*id]]`]]` &includeTVs=`1` &tvFilters=`menuGroup==topmenu` &tplFirst=`simpleIDfirst` &tpl=`simpleID` &depth=`0`]]`]]

        The getResources snippet returns exactly what Wayfinder needs; a line with ID’s (comma-seperated) of resources wich have a tv-value ’topmenu’ of the tv menuGroup. The problem is as described above; I want to load dynamic values in the includeDocs but when I set debug on I see an empty includeDocs.

        Does anyone has a solution for me?
          MODX Ambassador (NL) & Professional MODX developer
          Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
          MODX e-commerce solution SimpleCart
          • 16868
          • 24 Posts
          This is an ancient topic but I needed an answer to this exact question and now that I have one I’ll share it here.

          Actually it’s a simple problem. Just:

          1. Make a template variable (tv) that will identify the resources you want excluded. I chose a drop down list with Show==1||Don’t Show==2 kinda thing.

          2. Make a snippet that grabs the IDs of the resources that should be excluded based on the tv from the database. I hacked this from something else I found somewhere in the forum, forget where now:

          /* build a query to get Resources with a TV id of 2 that are published and not deleted */
          $query = $modx->newQuery('modTemplateVarResource', array('tmplvarid' => 1, 'value' => 2));
          
          /* to optimize, you can select only the columns you need */
          $query->select($modx->getSelectColumns('modTemplateVarResource', 'modTemplateVarResource', '', array('id', 'contentid', 'value')));
          
          /* get the modTemplateVarResource objects with a TV id of 1 */
          $children = $modx->getCollection('modResource', $query);
          
          /* loop through the children and push the id onto $resourceIds */
          $resourceIds = array();
          foreach ($children as $child) {
              $resourceIds[] = $child->get('contentid');
          }
          
          return implode(',', $resourceIds);​


          NOTE: You’ll have to go into the database to dig up the ’tmplvarid’ => 1 part on your own. The number is the ID of your template var. There’s a table for template variables that shows IDs, maybe there’s a way to refer to it directly. Not sure myself!

          3. Include an excludeDocs parameter in your Wayfinder call, and insert the snippet as the passed value. Like so:
          [[!Wayfinder? ...&startId, &level, etc... [color=red]&excludeDocs=`[[your_snippet_name_here]]`[/color]]]


          Done!

          And for people like me who were very confused for several weeks: This is for Revolution! Evo will take a tweek or two.