We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    That is a clever solution. As with everything in MODx there are several options. You could also use a wrapper snippet and include some simple logic to build a wrapper. Or, you could use the new ditto iteration feature with the total features with some support snippets to output something according to the condition.

    MODx’s flexibility is great.

    BTW - a wrapper snippet is a snippet that runs another snippet within it using the $modx->runSnippet() api function. There are several situations where this comes in very handy.
      [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]
      • 24495
      • 407 Posts
      And why not an outerTpl in a future version? wink Seems to me that this could be an important enhancement for all purposes listing parts of subdocs within a wrapper if result is not empty.
      ...
      Ok I’m back in my basement hobby room cool
        • 3749
        • 24,544 Posts
        Ditto uses a $header and $footer variable.

        The header and footer are added to the ends of the output.

        The default $header and $footer are in the file: assets/ditto/formats/htmlformat.inc.php as follows:

        <?php
        $header = "";
        $footer = "";
        ?>


        I’m not sure why they’re there since I don’t see any circumstance where they wouldn’t be empty but maybe I’m missing something.

        You could just edit them to be whatever you want for your outer tpl.  With no results, you get: $header.$noresults.$footer so you could just change that line to leave out the header and footer if you didn’t want them with no results (in The Ditto snippet itself).

        As a possibility for future Ditto versions, there could be an isset() line for the header and footer variables so that people could set them as parameters without them being over-ridden by the default empty strings although maybe an outerTpl that didn’t get ouput with no results would be better.

        As a side note, I didn’t spend that much time looking, but it kind of looks like when using formats other than html (e.g. RSS, json, XML), these two variables ($header & $footer) are never set although they’re still used in the snippet -- my old programming instructors would take off some points for this.  wink

          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
          • 24495
          • 407 Posts
          Sounds interesting. Could be the entrance to an enhancement? wink
          • And &displayStart to have a display for the start item! It is very handy for section menu headers in Wayfinder.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 9849
              • 74 Posts
              Any solution on that? I saw that it is checked for Ditto 2.5
              Unfortunately I can not wait that long. I thought there might be a way using PHx but therefore I need the total amount of documents being returned by Ditto!
              • If you just want to wrap your ditto output in custom stuff, just do that and put your call inside. Ditto is designed to just list things in a flat list (no nested hierarchies):
                <div id="myCustomDittoWrapper" class="myCustomClass">
                
                [[Ditto?parents=`1` ... ]]
                
                </div>
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 9849
                  • 74 Posts
                  Unfortunately I cannot wrap [!Ditto!] with custom code. As stated before if I want a list (ul, ol or dl) I cannot leave <ul></ul> without any <li>-elements. That’s semantically wrong!

                  I created a custom format with header and footer. All I need is a way to tell Ditto not to output anything if no documents were found. Not even header and footer! Is there a way? Via PHx maybe?
                    • 24495
                    • 407 Posts
                    [+phx:input=`[[Ditto?parents=`1` ... ]]`:is=``:then=``:else=`<ul>`+]
                    [[Ditto?parents=`1` ... ]]
                    [+phx:input=`[[Ditto?parents=`1` ... ]]`:is=``:then=``:else=`</ul>`+]

                    Is this what you looking for?
                      • 9849
                      • 74 Posts
                      That does not work. Although I specified the noResults parameter of Ditto to be "EMPTY" and put that inside the phx call (:is=`EMPTY`) it still outputs the input of :then.

                      By the way: It is a little bit wired to have three calls just to check if one call should be printed to screen or not.