We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49687
    • 1 Posts
    Hi!

    When I call getResources from If, TV inputs somwhere lost. There is no problem with TV's when I call getResources directly from conten.
    [[If?
        &subject=`[[*parent]]`
        &operator=`empty`
        &then=`
            [[!getResources? 
            &showHidden=`1` 
            &includeContent=`1` 
            &tpl=`news-list-tpl`
            &parents=`[[*id]]`
            &processTVs=`1` 
            &includeTVs=`1` 
            &tvPrefix=`` 
            &sortdir=`ASC` 
            &limit=`2`  
            &sortby=`{"publishedon":"DESC"}`
            ]]`
    ]]
    


    Any suggestions? [ed. note: sysadministrator last edited this post 11 years, 8 months ago.]
      • 3749
      • 24,544 Posts
      Yes, that whole getResources call is going to be evaluated and all of its output stored in memory whether it's used or not. That's going to be pretty slow and wasteful. Calling The If snippet uncached (!If) might make it work, but I don't think it's a good approach to begin with.

      One solution is to just have a different template for documents at the root. That would allow MODX to cache the results.

      If you're determined to have it be dynamic, I think I would do it this way (untested). Replace what you have above with this tag:

      [[!CheckParent]]


      Create this snippet called CheckParent (or whatever you like as long as it matches the tag):

      /* CheckParent snippet */
      
      /* do nothing for empty parent */
      if ($modx->resource->get('parent')) return '';
      
      /* Set getResources Properties */
      $fields = array(
          'showHidden' => '1',
          'includeContent' => '1',
          'tpl' => 'news-list-tpl',
          'parents' => $modx->resource->get('id'),
          'processTVs' => '1',
          'includeTVs' => '1',
          'tvPrefix' => '',
          'sortdir' => 'ASC',
          'limit' => '2', 
          'sortby' => '{"publishedon":"DESC"}',
      );
      
      /* Call getResources */
      return $modx->runSnippet('getResources', $fields);
      

        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