We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11681
    • 98 Posts
    I want Ditto to present the content of only the latest of a number of documents. I am able to achieve the desired result, but I don’t like its semantics.

    I am currently calling Ditto like this:
    [!Ditto?
      &id=`homeNews`
      &debug=`0`
      &parents=`5`
      &display=`1`
      &showPublishedOnly=`0`
      &orderBy=`createdon DESC`
      &tpl=`homeNewsTpl`
      &paginate=`0`
    !]

    I dislike this call because it "tricks" Ditto into presenting what I desire. It commands Ditto to present non-paginated results, order the results by descending creation date/time and just present one result, i.e. the latest document.

    Sure enough, when I look at the debugging window, I note that Ditto has actually retrieved every document in order to present just the latest one. This is wasteful and will increase page creation time as the number of documents grows.

    I want something straightforward and hopefully more efficient, such as a "&firstDocument" parameter. The converse "&lastDocument" would be useful, too.

    (Using Ditto to present the latest document is like swatting a fly with a large hammer. Certainly I could accomplish this directly via SQL. However, I am using Ditto elsewhere in the site anyway, and there is no guarantee that he who eventually supports the site will know about SQL.)

    Thanks in advance for your ideas!

    -- Halfnium
      I looked just like that in 1964.
      • 3749
      • 24,544 Posts
      &queryLimit=`1`
      smiley

      FYI, you can leave out most of the other parameters since they are the defaults. You’ll only need &parents, &showPublishedOnly, and &tpl.

      &id should only be necessary if you have multiple Ditto calls on the same page and &showPublishedOnly is only necessary if you really want to show unpublished docs.
        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
        • 11681
        • 98 Posts
        Thanks!

        Sorry, I could have cleaned up that example to make it more to the point.

        Yes, I am using more than one Ditto call on the same page. That’s related to why I want just the latest document: The home page will show just the latest instance from each of several doc collections (News, Events, Video ....) and invite the user to browse to paginated presentations of each collection. The idea is to make the home page a poor man’s portal to the whole site.
          I looked just like that in 1964.
          • 3749
          • 24,544 Posts
          Glad it worked. smiley

          Bear in mind that if you have Ditto show unpublished documents, links to them won’t work.
            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