We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47211
    • 6 Posts
    Hi.
    I'm using getPage with getResources. It returns all results I need with this code:
    [[!getPage? &elementClass=`modSnippet` &element=`getResources` &parents=`8` &showHidden=`1` &tpl=`chkresources` &includeContent=`1`  &includeTVs=`2`  &processTVs=`2` &sortby=`menuindex` &sortdir=`ASC` &limit=`12` &tvPrefix=`` &hideContainers=`1`  &pageLimit=`5`   &pageNavVar=`page.nav`]]

    I'm trying to get a message if there is no results. And for some strange reason it does not work. I put this code
    &element=`getResources:default="No Results"`
    instead of
    &element=`getResources`


    Thanks

    This question has been answered by multiple community members. See the first response.

    [ed. note: webpaul64 last edited this post 12 years, 6 months ago.]
      • 3749
      • 24,544 Posts
      Please highlight your code (snippet tags) and click on the <> icon in the toolbar so we can see the code clearly.

      The getPage snippet calls the getResources snippet something like this:

      $snipppet = $scriptProperties['element]';
      $modx->runsSnippet($snippet);


      So, if &element is set to `getResources`, that's the equivalent of this:

      $modx->runSnippet('getResources');


      In your case, though the &element property is set to `getResources:default="No Results"`, so it's trying to do the equivalent of this:

      $modx->runSnippet('getResources:default="No Results"');


      There is no snippet with that name, so you get no results.
        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
        • 47211
        • 6 Posts
        Thank you. Now I understand. So, my next question would be the following. Is it possible to display the message after there is no results returned from getResources if getResources is used with getPage.

        Thanks again
        • discuss.answer
          • 3749
          • 24,544 Posts
          You could try this. I'm not sure if it will work:

          [[!getPage:default="No Results"? 
              &elementClass=`modSnippet` 
              &element=`getResources` 
              &parents=`8` 
              &showHidden=`1` 
              &tpl=`chkresources` 
              &includeContent=`1`  
              &includeTVs=`2`  
              &processTVs=`2` 
              &sortby=`menuindex` 
              &sortdir=`ASC` 
              &limit=`12` 
              &tvPrefix=`` 
              &hideContainers=`1`  
              &pageLimit=`5`   
              &pageNavVar=`page.nav`
          ]]


          If it doesn't this might:


          [[!+MyResults:default="NoResults"]]


          [[!getPage:default="No Results"? 
              &toPlaceholder=`MyResults`
              &elementClass=`modSnippet` 
              &element=`getResources` 
              &parents=`8` 
              &showHidden=`1` 
              &tpl=`chkresources` 
              &includeContent=`1`  
              &includeTVs=`2`  
              &processTVs=`2` 
              &sortby=`menuindex` 
              &sortdir=`ASC` 
              &limit=`12` 
              &tvPrefix=`` 
              &hideContainers=`1`  
              &pageLimit=`5`   
              &pageNavVar=`page.nav`
          ]]


          If neither of those works, see if you can post the actual code returned from getPage when there are no results by wrapping the tag in pre tags.
            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
            • 47211
            • 6 Posts
            Thanks a lot!!!
            [[!getPage:default=`No Results`? 
            &elementClass=`modSnippet` 
            &element=`getResources` 
            &parents=`8` 
            &showHidden=`1` 
            &tpl=`chkresources` 
            &includeContent=`1` 
            &includeTVs=`2`  
            &processTVs=`2` 
            &sortby=`menuindex` 
            &sortdir=`ASC` 
            &limit=`12` 
            &tvPrefix=`` 
            &hideContainers=`1`  
            &pageLimit=`5`  
            &pageNavVar=`page.nav`]]
            

            Here it is. Works as it should. [ed. note: webpaul64 last edited this post 12 years, 6 months ago.]
              • 3749
              • 24,544 Posts
              I'm glad to hear it. I really didn't think it would be that simple. wink

              BTW, it's completely up to you, but I find that formatting my snippet calls as in my post above makes it much easier to maintain them. MODX parses them fine that way.
                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
                • 47211
                • 6 Posts
                Absolutely! I'll do it next time. Just a simple addition. Instead of
                :default=`No Results`
                better to use a chunk
                :default=`[[$chkempty]]`


                The best solutions are the simple ones.