We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50574
    • 70 Posts
    Can I remove certain child IDs from either a TV input option @EVAL or from the output that the TV returns?
    TV input:
    @EVAL return $modx->runSnippet('listProducts',array('parent:IN' => array(2,76)));

    Output:
    $c = $modx->newQuery('modResource');
    $parents = $modx->getOption('parents', $scriptProperties, '2,76', true);
    $parents = explode(',', $parents);
    $c->where(array(
        'parent:IN' => $parents,
    ));
    $resArray = $modx->getCollection('modResource', $c);
    if (empty($resArray)) {
       return 'No products found';
    }
    foreach($resArray as $res) {
        $resources[] = $res->get('pagetitle') . '==' . $res->get('id');
    }
    $out = implode("||",$resources);
    return $out;

    This populates a checkbox list. There are some children in here that I need to be able show them in the navigation but I don't want them to show as option in the checkbox list.

    Thanks

    This question has been answered by cottoncreative. See the first response.

      • 3749
      • 24,544 Posts
      I think this would do it (untested):


      @EVAL return $modx->runSnippet('listProducts',array('parents' => '2,76', 'skip' => 3,22,43));



      
      $c = $modx->newQuery('modResource');
      $parents = $modx->getOption('parents', $scriptProperties, '2,76', true);
      $parents = explode(',', $parents);
      $skip = $modx->getOption('skip', $scriptProperties, '12,33,44', true);
      $skip = explode(',', $skip);
      
      $c->where(array(
          'parent:IN' => $parents,
      ));
      $resArray = $modx->getCollection('modResource', $c);
      if (empty($resArray)) {
         return 'No products found';
      }
      foreach($resArray as $res) {
          $docId = $res->get('id');
          if (in_array($docId, $skip)) {
              continue;
          }
          $resources[] = $res->get('pagetitle') . '==' . $docId;
      }
      $out = implode("||",$resources);
      return $out;
      [ed. note: BobRay last edited this post 8 years, 8 months ago.]
        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
        • 50574
        • 70 Posts
        Hi Bob

        Thanks for the above, I've only just managed to get back round to looking at this again.
        I think the key part of this is the parent:IN because if it doesn't use that it only shows the first resource in the array (for both 'parent' & 'skip'). Can something similar be done with skip:IN?

        I tried a few iterations but nothing's come up trumps yet.
        @EVAL return $modx->runSnippet('listProducts',array('parent:IN' => array(2,76), 'skip:IN' =>array(12, 33, 44)));

        $c = $modx->newQuery('modResource');
        $parents = $modx->getOption('parents', $scriptProperties, '2,76', true);
        $parents = explode(',', $parents);
        $skip = $modx->getOption('skip', $scriptProperties, '12,33,44', true);
        $skip = explode(',', $parents);
        $c->where(array(
            'parent:IN' => $parents,
            'skip:IN' => $parents,
        ));
        $resArray = $modx->getCollection('modResource', $c);
        if (empty($resArray)) {
           return 'No products found';
        }
        foreach($resArray as $res) {
            $resources[] = $res->get('pagetitle') . '==' . $res->get('id');
        }
        $out = implode("||",$resources);
        return $out;
          • 3749
          • 24,544 Posts
          Take another look at this:

          @EVAL return $modx->runSnippet('listProducts',array('parents' => '2,76', 'skip' => 3,22,43));


          Notice that you don't put the :IN here, just property name and the comma-separated list of numbers.

          There's a mistake in my code above. It should be:

          $c = $modx->newQuery('modResource');
          $parents = $modx->getOption('parents', $scriptProperties, '2,76', true);
          $parents = explode(',', $parents);
          $skip = $modx->getOption('skip', $scriptProperties, '12,33,44', true);
          $skip = explode(',', $skip);
           
          $c->where(array(
              'parent:IN' => $parents,
          ));
          $resArray = $modx->getCollection('modResource', $c);
          if (empty($resArray)) {
             return 'No products found';
          }
          foreach($resArray as $res) {
              $docId = $res->get('id');
              if (in_array($docId, $skip)) {
                  continue;
              }
              $resources[] = $res->get('pagetitle') . '==' . $docId;
          }
          $out = implode("||",$resources);
          return $out;



          IOW,

          $skip = explode(',', $parents);

          should be:
          $skip = explode(',', $skip);
            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
            • 3749
            • 24,544 Posts
            (See post above)

            BTW, I believe this would work also and would be a little faster (untested):

            $c = $modx->newQuery('modResource');
            $parents = $modx->getOption('parents', $scriptProperties, '2,76', true);
            $parents = explode(',', $parents);
            $skip = $modx->getOption('skip', $scriptProperties, '12,33,44', true);
            $skip = explode(',', $skip);
             
            $c->where(array(
                'parent:IN' => $parents,
                'parent:NOT IN' => $skip,
            ));
            $resArray = $modx->getCollection('modResource', $c);
            if (empty($resArray)) {
               return 'No products found';
            }
            $resources = array();
            foreach($resArray as $res) {
                $docId = $res->get('id');
                $resources[] = $res->get('pagetitle') . '==' . $docId;
            }
            $out = implode("||",$resources);
            return $out;
              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
            • discuss.answer
              • 50574
              • 70 Posts
              Thank you, I was getting hung up on the :IN part when it wasn't necessary.
              The first snippet is the one I'm using, the second I couldn't get to work.

              I did notice a few things that may be of use to others so here's my final code and an explanation.

              In my structure I have #2 as the main product container housing resources as well as a sub-container, #76, which also has resources inside. The TV input @EVAL binding is the important part, with regards to the numbers to include and to skip. I can tell it to pull the resources from the sub-container (76) and can then tell it to skip 76 without stopping the resources within it being shown.
              @EVAL return $modx->runSnippet('listProducts',array('parents' => '2,76', 'skip' => '166,71,74,98,73,75,76,77'));

              The listProduct Snippet then doesn't seem to need the same 'array' list to be included for it to work so I've just used a number from the array as a fallback.
              $c = $modx->newQuery('modResource');
              $parents = $modx->getOption('parents', $scriptProperties, '2', true);
              $parents = explode(',', $parents);
              $skip = $modx->getOption('skip', $scriptProperties, '77', true);
              $skip = explode(',', $skip);
                
              $c->where(array(
                  'parent:IN' => $parents,
              ));
              $resArray = $modx->getCollection('modResource', $c);
              if (empty($resArray)) {
                 return 'No products found';
              }
              foreach($resArray as $res) {
                  $docId = $res->get('id');
                  if (in_array($docId, $skip)) {
                      continue;
                  }
                  $resources[] = $res->get('pagetitle') . '==' . $docId;
              }
              $out = implode("||",$resources);
              return $out;


              Thanks again to Bob for your patience.
                • 3749
                • 24,544 Posts
                Yes, explode() will still turn the single number into an array:

                array(
                  [0] => "77"
                )

                  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