We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10226
    • 412 Posts
    So when a working ditto call has no documents, we get "No documents Found" or something similar. Is there a way to display a chunk when there is no child documents present?

    Thanks!
      • 7231
      • 4,205 Posts
      Use the &noResults parameter:

      noResults
      Purpose

      Text or chunk to display when there are no results
      Options

      Any valid chunk name or text
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 10226
        • 412 Posts
        Ahh... figured it was that easy, just didn’t recall anything in the docs!

        *slaps himself with RTFM!*

        Thanks!
          • 10226
          • 412 Posts
          well this works well, but how can it work with pagination? is there a variable that can be passed to pagination to tell it not to display when there is no data?
            • 18397
            • 3,250 Posts
            Unfortunately, that is not possible at this time. However, a ticket has already been created for this:
            http://mirror3.cvsdude.com/trac/ditto/codebase/ticket/86
              • 33357
              • 10 Posts
              Same question here

              I want to show some filtered documents (say, news list for current document’s tags).
              That’s what I have

              <h3>Related news</h3>
              [!Ditto...!]

              But I don’t whant that "related news" heading when there’s no results. Actually, I don’t want anything to be shown in this case. I can set &noResults to some empty chunk, but how to get rid of this heading?

              Can this be done without using &save and writing my own snippet to check if there’s a result set so I can add a heading?
                • 18397
                • 3,250 Posts
                You could put the related news heading in &tplFirst so it would look like
                <h3>Related News</h3>
                ...Ditto Template Goes Here...
                
                  • 33357
                  • 10 Posts
                  actuallty I tried that
                  problem is, when there’s only one row returned, there’s no "first" record, just "last"
                  I’m using 2.0.2. Well, I was using it. Right now I’m installing 2.1b3 to see if it’s better fits my needs.

                  OK

                  Here’s my solution (using 2.1b3 and ditto_iteration placeholder)
                  custom &tpl + &noResult=` `

                  
                  [+ditto_iteration:is=`0`:then=`<h5>News</h5><ul>`+]
                  
                  <li class="ditto_item" id="ditto_item_[+id+]"><a href="[~[+id+]~]">[+pagetitle+]</a></li>
                  
                  [+ditto_iteration:is=`[+total+]-1`:then=`</ul>`+]