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

    Firstly, please refer to this post as I require something very similar:
    http://modxcms.com/forums/index.php/topic,38172.0.html

    Essentially I am doing the same thing: I need to run a nested Ditto call, that will only return results if a child has children.
    In my situation, I am going down an extra level and need to single out whether a specific child has children of it’s own.

    Here’s my tree:

    Productions
    - Production 1
    --- Container 1
    ----- Child
    ----- Child
    ----- etc.
    --- Container 2
    ----- Child
    ----- Child
    ----- etc.
    --- Container 3
    ----- Child
    ----- Child
    ----- etc.
    - Production 2
    --- Container 1
    ----- Child
    ----- Child
    ----- etc.
    --- Container 2
    ----- Child
    ----- Child
    ----- etc.
    --- Container 3
    ----- Child
    ----- Child
    ----- etc.
    -etc.

    I will have a Ditto call (with a nested Ditto call within it’s template, I presume), that loops though each Production and sees whether Container 3 has children:
    If Container 3 has children, the Ditto call uses it’s template to present the image/info of the Production, and a list of the children of Container 3.
    If Container 3 has no children, Ditto returns nothing for that Production.

    The children of Container 3 that are listed need to be ordered by a date TV (easy enough).

    Container 3 and it’s children will all be using a specific template, if that helps.


    As mentioned, this is time critical, need this done in the next few days.
    Please get in touch asap via this thread or directly at [email protected]
    Payment is via Paypal, 50% upfront, 50% on completion.


    Thanks,

    David
    Melbourne, Australia
      • 1122
      • 209 Posts
      I think that first of all you need to read another similar thread -- http://modxcms.com/forums/index.php/topic,38339.0.html -- and you will be able to manipulate recursion and... save your money. If not, you can email or PM me, let’s say, an hour ahead of your deadline and I will solve this in a single (recursive) step. I am based in Europe.
        • 16845
        • 26 Posts
        Thanks, I’ll look into this this evening.
          • 16845
          • 26 Posts
          Hi alik,

          Thanks for you response.

          I like to try and fix things myself, but am stuck on this one. I’ve read the thread you linked to and tried quiet a few different variations and cannot get it to work...

          Just to make sure I’ve been clear, I have attached a snapshot of the tree structure. Productions will be the parent of the Ditto call, and it needs to loop through each Production. If one of the Screenings folders has children (in this screenshot two do, and one doesn’t), then we’ll create a block with:
          -An image/name of the Production (pagetitle and a TV from doc 109 in this tree)
          -a list with each of the three Screenings (docs 19, 7 and 18 in this tree)

          If the Screenings folder is empty (as is doc 96 in this tree), we’ll make no block at all.

          Can this work with straight Ditto calls, or does it need a custom snippet?

          On a very tight deadline and don’t have the time to figure this one out.
          Can you help, happy to compensate...

          Thanks in advance
            • 1122
            • 209 Posts
            OK, public reply to my post then providing solution to the whole public...
            main Ditto call -> grab all Screenings docs
            
            [[Ditto? &parents=`2` &depth=`2` &filter=`pagetitle,Screenings,1` &tpl=`ChildrenSearch`]]
            
            ----
            
            content of ChildrenSearch chunk -> search for children within single Screenings
            
            <div id="prod_[+id+]" style="display: block;">
            [[Ditto? &documents=`[+parent+]` &tpl=`Header`]]
            <ul>[[Ditto? &parents=`[+id+]` &depth=`1` &tpl=`List` &noDocuments=`HideThis`]]</ul>
            </div>
            
            ----
            
            content of Header chunk -> render listing header (give some style to it :)
            [+your-tv-image+]
            [+pagetitle+]
            
            ----
            
            content of List chunk -> render the list itself
            <li>[+pagetitle+] + whatever you need</li>
            
            ----
            
            content of HideThis chunk -> hide empty list
            
            <script type="text/javascript">
            <!--
            var thisProd = document.getElementById('prod_[+id+]');
            thisProd.style.display = 'none';
            -->
            </script>
            

            Done.
            One remark though. I have not tested this, but in theory it would be safer to distinguish two Ditto calls in "ChildrenSearch" chunkd with &id=`header` and &id=`list` parameters.
              • 16845
              • 26 Posts
              Wow, thanks a million alik, this solution works a treat.
              Nothing like a bit of Javascript to spice up your day!

              But seriously, it’s a great solution because it leaves Ditto untouched and therefore fully featured.

              I changed &noDocuments to &noResults in the ChildrenSearch chunk for it to work at my end.

              One small issue, is I can’t get Ditto to load a noResults chunk if there are no Screenings at all.
              Is that possible, or is everything being hidden by the JS, even a valid noResults chunk?

              Thanks in advance,

              David
                • 20413
                • 2,877 Posts
                  @hawproductions | http://mrhaw.com/

                  Infograph: MODX Advanced Install in 7 steps:
                  http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                  Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                  http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower