We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39501
    • 163 Posts
    I have nested getUrlParam inside getResources, so I can filter my results based on URL.

    There is an IF statement...if somebody is on the homepage, the results show as normal. If there is a url parameter it will filter the results accordingly.

    Can anybody see where i'm going wrong?

    I have forced getResources to output an array of attributes. If I put the IF statement back into the snippet call, the array disappears, which makes things hard to trouble shoot!

    [[!getResources? 
      &sortby=`` 
      &parents=`[[UltimateParent?]]` 
      &includeTVs=`1` 
      &processTVs=`1` 
      &tvPrefix=`` 
      &tpl=`tpl.gr.section.news.box`
      [[!If?
        &subject=`[[!getUrlParam? &name=`category` &int=`0`]]`
        &operator=`notempty`
        &then=`&tvFilters=`tv.content.news.cat==[[!getUrlParam? &name=`category` &int=`0`]]``
        &else=``
      ]]
      &debug=`1`
    ]]

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

    [ed. note: jonleverrier last edited this post 12 years, 8 months ago.]
      • 39501
      • 163 Posts
      I've tried this logic to. Tested the IF statement outside of the snippet call to make sure it was working..

      [[!getResources? 
        &sortby=`` 
        &parents=`[[UltimateParent?]]` 
        &includeTVs=`1` 
        &processTVs=`1` 
        &tvPrefix=`` 
        &tpl=`tpl.gr.section.news.boxa`
        [[!If?
          &subject=`[[!getUrlParam? &name=`category` &int=`0`]]`
          &operator=`isempty`
          &then=``
          &else=`&tvFilters=`tv.content.news.cat==[[!getUrlParam? &name=`category` &int=`0`]]``
        ]]
        &debug=`1`
      ]]
        • 39501
        • 163 Posts
        I've managed to find a work around:

        [[!getResources:if=`[[!getUrlParam? &name=`category` &int=`0`]]`:notempty=`
        
        [[!getResources? 
          &sortby=`` 
          &parents=`[[UltimateParent?]]` 
          &includeTVs=`1` 
          &processTVs=`1` 
          &tvPrefix=`` 
          &tpl=`tpl.gr.section.news.box`
          &tvFilters=`tv.content.news.cat==[[!getUrlParam? &name=`category` &int=`0`]]`
        ]]
        
        `
        ]]
        
        [[!getResources:if=`[[!getUrlParam? &name=`category` &int=`0`]]`:isempty=`
        
        [[!getResources? 
          &sortby=`` 
          &parents=`[[UltimateParent?]]` 
          &includeTVs=`1` 
          &processTVs=`1` 
          &tvPrefix=`` 
          &tpl=`tpl.gr.section.news.box`
        ]]


        Would this code effect performance?
          • 4172
          • 5,888 Posts
          Would this code effect performance?


          yes, this would run every snippet-call on this construct, everytime the page is loaded.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 39501
            • 163 Posts
            Quote from: Bruno17 at Jan 30, 2014, 11:17 AM
            Would this code effect performance?


            yes, this would run every snippet-call on this construct, everytime the page is loaded.

            Thanks for confirming Bruno. There are flaws in my last example anyway sad back to the drawing board.
            • discuss.answer
              • 3749
              • 24,544 Posts
              I think I would just put all of that logic into a snippet. I think this would be it:


              <?php
              $category = isset($_GET['category']) && (!empty($_GET['category']))
                      ? $_GET['category']
                      : '';
              
              $fields = array(
                  'includeTVs' => true,
                  'processTVs' => true,
                  'tvPrefix'   => '',
                  'tpl'        => 'tpl.gr.section.news.box',
              );
              
              $fields['parent'] = $modx->runSnippet('UltimateParent');
              if ($category) {
                  $fields['tvFilters'] = 'tv.content.news.cat==' . $category;
              }
              
              return $modx->runSnippet(getResources, $fields);
              [ed. note: BobRay last edited this post 12 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
                • 4172
                • 5,888 Posts
                I think, it should be

                return $modx->runSnippet('getResources',$fields);
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 39501
                  • 163 Posts
                  Thanks @bobray @bruno17

                  Will test and try and report back!