We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Hi - I need to be able to have a getResources call fetch ALL the children of a specified parent and output them all APART from those which have their IDs listed in a TV (fetchedLIST). Is this possible?

    So fetchedLIST TV will output: 1,12,34,78 for example - these being the IDs of the resources to ignore in the getResources call

    So, in effect a way of having resources=`-[[*fetchedLIST]]` but needing to add a - before EACH of the IDs returned by TV fetchedLIST

    So if I had resources in the parent resource 12 with ids: 1,2,3,4,12,34 and 78

    I would want my getResources call to just display those from the group above, that ARE NOT included in the fetchedLIST TV - so not 1,12,34 and 78 - so the output of the getresources call would be the data for JUST resources ID: 2,3 and 4


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

    [ed. note: dubbs last edited this post 5 years, 10 months ago.]
      • 36582
      • 463 Posts
      Could you use 'where' query? In effect something like...

      $query->where(array(‘id:!=‘ => array([[*fetchedLIST]])));


      https://docs.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.where
        Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk
        • 8168
        • 1,118 Posts
        Quote from: chrisandy at Nov 15, 2018, 02:17 PM
        Could you use 'where' query? In effect something like...

        $query->where(array(‘id:!=‘ => array([[*fetchedLIST]])));


        https://docs.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.where

        Theory sounds good - how would that get pushed into the &resources field of getResources though?
          • 36582
          • 463 Posts
          I'd have thought you'd use &parents rather than &resources and then apply the 'where'. I'm not sure what the syntax would be for the query though, especially with a custom tv - maybe you'll need a snippet?
            Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk
            • 8168
            • 1,118 Posts
            Quote from: chrisandy at Nov 15, 2018, 04:07 PM
            I'd have thought you'd use &parents rather than &resources and then apply the 'where'. I'm not sure what the syntax would be for the query though, especially with a custom tv - maybe you'll need a snippet?

            I use the parents to set the resource parent which holds the resources to be fetched - then use the resources to specify which to remove/display.

            Anyone any ideas on the syntax to use to get the where parameters to work? There is very little documentation illustrating this?
              • 3749
              • 24,544 Posts
              I think this might do it:


              &resources = `-[[GetFetchedList]]`


              /* GetFetchedList snippet */
              $docs = $modx->resource->getTTValue('fetchedLIST');
              return str_replace(','. ',-', $docs);
              


              The snippet result will be cached, so it probably won't work correctly if the getResources tag is on multiple pages where the TV has different values. In that case, I think an uncached custom snippet that either gets the resources directly (best if the getResources tag is simple) or calls getResources with $modx->runSnippet() would work.

              I could probably knock it out for you if I can see your full getResources tag.
                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
                • 8168
                • 1,118 Posts
                Quote from: BobRay at Nov 15, 2018, 06:29 PM
                I think this might do it:


                &resources = `-[[GetFetchedList]]`


                /* GetFetchedList snippet */
                $docs = $modx->resource->getTVValue('fetchedLIST');
                return str_replace(','. ',-', $docs);
                


                The snippet result will be cached, so it probably won't work correctly if the getResources tag is on multiple pages where the TV has different values. In that case, I think an uncached custom snippet that either gets the resources directly (best if the getResources tag is simple) or calls getResources with $modx->runSnippet() would work.

                I could probably knock it out for you if I can see your full getResources tag.

                Thanks Bob - for some reason I get a blank page when I add this code in - server error in the code somewhere? Error seems to be in snippet - as page renders when i clear snippet code?

                getResources code call is:

                [[getResources? &parents=`49` &tpl=`ItemTpl` &depth=`1` &limit=`9999999999` &includeTVs=`1` &processTVs=`0` &tvPrefix=`` &sortby=`RAND()` &showHidden=`1` &resources=`-[[GetFetchedList]]` ]]
                
                [ed. note: BobRay last edited this post 5 years, 10 months ago.]
                  • 8168
                  • 1,118 Posts
                  Found the issue - getTVValue was written as getTTValue wink so no server error now - but it doesnt work for some reason still fetches all results?
                  • discuss.answer
                    • 8168
                    • 1,118 Posts
                    Fixed it wink Snippet code as below works wink

                    Snippet Name: getfetchedList

                    $page = $modx->getObject('modResource', 48);
                    $docs = $page->getTVValue('fetchedLIST');
                    $docs = str_replace(",", ",-", $docs);
                    echo $docs;
                    


                    And getResources call for those looking to do similar...

                    [[!getResources? &parents=`49` &tpl=`elementTpl` &depth=`1` &limit=`9999999999` &includeTVs=`1` &processTVs=`0` &tvPrefix=`` &sortby=`RAND()` &showHidden=`1` &resources=`-[[!getfetchedList]]` ]]
                    
                      • 8168
                      • 1,118 Posts
                      Thanks for the assistance once more Bob. A true MODx leg.end!