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

    I have some troubles with Ditto and the randomize parameter. My document id "3" holds a large amount of subdocuments (game reviews). Now I want get the 10 newest documents, depending on the latest release dates of those games. My TV "SpieleRelease" is holding the release date, and the TV "SpieleWertungGesamt" is holding the score. The following Ditto call works fine to get only the latest released game that has been reviewed:

    [[Ditto? &startID=`3` &sortBy=`SpieleRelease` &filter=`SpieleWertungGesamt,-,2` &dateFormat=`%A, %d. %b %Y, %H:%M Uhr` &sortDir=`DESC` &total=`1` &showPublishedOnly=`1` &showInMenuOnly=`1` &tpl=`iiiReviewHomeTpl`]]


    But now I do not want to have this limitation, instead I want to have one of the latest 10 reviewed releases showing randomly. I tried the following Ditto call:

    [[Ditto? &startID=`3` &sortBy=`SpieleRelease` &filter=`SpieleWertungGesamt,-,2` &dateFormat=`%A, %d. %b %Y, %H:%M Uhr` &sortDir=`DESC` &total=`10` &display=`1` &showPublishedOnly=`1` &showInMenuOnly=`1` &tpl=`iiiReviewHomeTpl` &randomize=`1`]]


    It does randomize the output, but it doesn’t recognize the limitation of 10 latest releases - the output shows a random review picked out of the complete document tree. So is there any possibility to get the latest 10 documents first and randomize those instead of the whole subtree?
      L.net Web Solutions
      Professional webdesign and development with MODX and WordPress.
      • 36624
      • 535 Posts
      you can use 2 nested call of Ditto.

      [[Ditto &documents=`[!Ditto? &total=`10` &tpl=`[+id+]`!]` &randomize=`1` ]]

      should work but not verified.
        CTRL+SHIFT+U - Clear Cache
        CTRL+SHIFT+H - Hiding Heft Panel
        CTRL+SHIFT+N - Fast Create Resource
        CTRL+ALT+P - Preview Recource (in edit resorce window)
        CTRL+ALT+S - Save
        • 21078
        • 77 Posts
        Thank you! But there seems to be a problem nesting another Ditto call sad

        When I hard code the documents like the following example, then it works correctly:

        [[Ditto? &documents=`2055,2032,1927,1884` &dateFormat=`%A, %d. %b %Y, %H:%M Uhr` &display=`1` &showPublishedOnly=`1` &showInMenuOnly=`1` &tpl=`iiiReviewHomeTpl` &randomize=`1`]]


        While trying to nest the Ditto call I get just an error response "No documents found.":

        [[Ditto? &documents=`[!Ditto? &parents=`3` &filter=`SpieleWertungGesamt,-,2` &orderBy=`SpieleRelease DESC` &total=`10` &tpl=`iiiJustIDs`!]` &dateFormat=`%A, %d. %b %Y, %H:%M Uhr` &display=`1` &showPublishedOnly=`1` &showInMenuOnly=`1` &tpl=`iiiReviewHomeTpl` &randomize=`1`]]


        (My tpl iiiJustIDs just holds "[+id+],")

        Any ideas?! huh
          L.net Web Solutions
          Professional webdesign and development with MODX and WordPress.
          • 10449
          • 956 Posts
          Don’t really have time to reproduce your situation on my local dev install, but I’d try one of the following things:

          a) Work with the Ditto "save" parameter. This allows you to have a first Ditto call that doesn’t render anything in the frontend. Instead, it will hold (save) some variables for you, that you can use in a 2nd Ditto call.
          Here’s a few forum threads with examples etc.:
          http://modxcms.com/forums/index.php?topic=20929.0
          http://modxcms.com/forums/index.php?topic=41876.0
          http://modxcms.com/forums/index.php?topic=44602.0

          b) Perhaps you can define / create a phx filter? http://wiki.modxcms.com/index.php/PHx

          c) Maybe you can create a custom Ditto filter? http://ditto.modxcms.com/tutorials/basic_filtering.html

            • 36624
            • 535 Posts
            ok, just tested what i said before and it works.. well you need to adjust a bit smiley

            this one grab 2 doc in parent 33 and then randomize :

            [!Ditto? &documents=`[[Ditto? &parents=`33` &total=`2` &tpl=`justId` &tplLast=`justIdLast`]]` &randomize=`1`!]

            Please note: [!...[[...]]....!]

            And you need to output ids like this "1,2,3,4,5,6" so a tpl with just "[+id+]," is not enough. you need to make another tpl for the last element with &tplLast (in our case "[+id+]" without the ",").

            if you dont want to use a chunk for only the Id, you normally can do that

            &tpl=`@CODE:[+id+],` &tplLast=`@CODE:[+id+]`

            (in my tests this broke the sql queries.. weird.. but should work! wink

            more: bruno made a simple but effective examples who run ditto with $modx->runSnippet(’Ditto’,$params);.



              CTRL+SHIFT+U - Clear Cache
              CTRL+SHIFT+H - Hiding Heft Panel
              CTRL+SHIFT+N - Fast Create Resource
              CTRL+ALT+P - Preview Recource (in edit resorce window)
              CTRL+ALT+S - Save
              • 21078
              • 77 Posts
              Hey, thanks a lot guys!

              I was also playing around with my Ditto call and tried something different which works too:

              [[Ditto? &parents=`3` &filter=`SpieleWertungGesamt,-,2` &where=`editedon > (unix_timestamp(now())-2629743)` &dateFormat=`%A, %d. %b %Y, %H:%M Uhr` &orderBy=`SpieleRelease DESC` &total=`1` &display=`1` &showPublishedOnly=`1` &showInMenuOnly=`1` &tpl=`iiiReviewHomeTpl` &randomize=`1`]]


              I added the &where parameter which filters my documents that have been edited within the last four weeks ... combined with the other parameters and &randomize outputs a random game review out of a set of current documents. smiley
                L.net Web Solutions
                Professional webdesign and development with MODX and WordPress.