We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    Currently running MODX Revolution 2.1.3-pl

    I'm using a snippet I found on the forums here to show/hide pages in Wayfinder based on the option selected in a TV. It has been working great, except that when a parent resource is hidden from the menu, it hides all of the children resources. Even if their TV option is set to have them show.

    So the simplest solution, does Wayfinder have a way to bypass that sort of thing?

    I also attempted to adapt the script to work with getResources, which was unsuccessful. So if there is no way for Wayfinder to work that way, is there another plugin that this functionality can be applied to?

    Here is the SidebarShow snippet, which is returning the id's of resources that have "No" selected in the template variable.

    <?php
    /* build a query to get Resources with a TV id of 2 that are published and not deleted */
    $query = $modx->newQuery('modTemplateVarResource', array('tmplvarid' => 14, '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);


    And, here is my Wayfinder call.

    [[!Wayfinder? &startId=`0` &level=`3` &excludeDocs=`[[SidebarShow]]` &ignoreHidden=`1`]]


    Finally, here is the getResources call I attempted to use. I tried to edit my SidebarShow snippet to add dashes in front of each page id, but I don't believe I got it working correctly.

    [[!getResources? &parents=`0` &resources=`[[SidebarShowGetResources]]` &tpl=`sidebarMenuTpl`]]


    I appreciate any help. If there is a cleaner way to do all of this, I'm open to that as well.
      • 36760
      • 136 Posts
      I guess another way to look at this would be if there is a way to tell getResources to only include pages whose ID's are listed in the "resource" parameter?

      I got the snippet to output the ID's of resources that are set to "Yes" in the TV, but getResources is still showing all of my pages.