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

    I'm using a slightly modified version of a script I found here to show or hide pages based on whether or not "yes" or "no" is selected in a TV.

    Currently, the snippet is putting out a list of resource ID's that should be shown in the menu.

    <?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' => 1));
      
    /* 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);


    I originally had this working with Wayfinder, but I needed child pages to show even if the parent page was hidden. I think getResources can do that (if it can't, let me know, that's what I was trying to test with this).

    The only problem is, even when I return the list of ID's in the resources parameters (as per below), getResources still shows all of the pages on my website. Is there a way to make it only show resources in the parameter, or am I just completely misunderstanding how all of this is coming together?

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


    I appreciate any help. [ed. note: firebot6 last edited this post 14 years, 11 months ago.]
      • 22427
      • 793 Posts
      As far as I understand it, getResources would respect both of your parameters, &resources and &parents. Because you say
      &parents=`0`
      it will display all children of your root resource.
      Just omit the &parents parameter, and it should be ok: The output will be restricted to the resources determined by your snippet.
        • 36760
        • 136 Posts
        That did the trick. I hadn't thought of it that way. Thanks!
          • 22303 MODX Staff
          • 10,725 Posts
          Actually, if you don't set the parents property, it assumes the current Resource. If you truly ONLY want the Resources listed in the resources property, set parents to -1 or another invalid Resource id, e.g.

          &parents=`-1`
            • 36760
            • 136 Posts
            That answers my question I was just coming back to ask!

            Child pages were showing up on parent pages even when they weren't set to show. Setting &parents to -1 fixed it.

            Thanks.
              • 22427
              • 793 Posts
              if you don't set the parents property, it assumes the current Resource.
              Oh, I see. Thanks for the hint to use
              &parents=`-1`