We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4750
    • 28 Posts
    Does anyone know how to show only certain pages in GetPages?

    I know that you can exclude by using &resources, [[!getResources? &parents=`5` &resources=`-10` &tpl=`myRowTpl`]]

    But I need to do a search that I will probably have to write in mysql then I can get the id’s and use modx to show the content with paging,

    Any help?
      • 3749
      • 24,544 Posts
      Can you describe the search criteria? There may be a way to do it with getResources.

      getPage doesn’t do any selection. It passes the properties in the tag on to whatever snippet you name (getResources in your example) and formats the output.

      You can replace getResources with your own snippet.
        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
        • 4750
        • 28 Posts
        Hi, I would like to show the results of a search with a template variable that is above a certain amount and below a certain amount. But when I do it at the moment it takes a long time to load, as I think it is loading all the template variables to load. So what I was thinking was loading only the id’s or only loading the ones in the page.
          • 3749
          • 24,544 Posts
          I think the most efficient method would be a custom snippet to select the resource IDs. That way, getResources doesn’t have to process anything but the selected resources and the resources won’t have to be retrieved just to test the TV values.

          Something like this (untested):

          [[!getResources?
              &resources=`[[!SelectResources? &tvId=`7` &parentId=`5` &tvMinValue=`3` &tvMaxValue=`7`]]` 
              &tpl=`MyTpl` 
          ]]


          <?php
          /* SelectResources snippet 
            *
            * Returns a comma-separated list of selected
            * resource IDs
            */
          $min = $scriptProperties['tvMinValue'];
          $max = $scriptProperties['tvMaxValue'];
          $tv = $modx->getObject('modTemplateVar', $scriptProperties['tvId]');
          
          /* get children of the parent */
          $docIds = $modx->getChildIds($scriptProperties['parentId']);
          
          foreach($docIds as $docId) {
               $tvVal = $tv->getValue($docId);
                if ($tvVal >= $min && $tvVal <= $max) {
                     $resourcesIds[] = $docId);
                }
          }
          
          return implode(',', $resourceIds);


          Once you have it working, you should be able to use getPage to format it as in the example here: http://rtfm.modx.com/display/ADDON/getResources#getResources-SelectionProperties.

          You might have to play with which snippets are cached or uncached and/or the getPage caching properties.

            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
            • 4750
            • 28 Posts
            Great, will try that, thanks,

            I think that I have to use GetPage because of the paging, but will see how far I get,