We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10313
    • 375 Posts
    Hi, I am just wondering if there is a way to tell Ditto to put a surrounding DIV or something else around all its output elements. I know I could output it myself, but I would find it nicer sometimes if Ditto could do it for me. Ditto can do so much wink

    Martin
      • 7231
      • 4,205 Posts
      No, Ditto returns a flat file structure. You can use the tplFirst and tplLast and include the pseudo outer information in these tpls. Note that this will break if there is only one item returned since it will only display the first.
        [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]
        • 10313
        • 375 Posts
        OK, thank you!
        • A good way to deal with this is to have a chunk (or a TV) with your outer container elements enclosing the Ditto snippet call.
            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
            • 10313
            • 375 Posts
            Yes, that’s exactly what I already did before. But now, I’m having a different page where I need several Ditto calls with different parents (different from the current documentId. So this chunk-thing would not work for me.

            Thanks anyway
            Martin
              • 24495
              • 407 Posts
              @sottwell: but not the best way. If you deliver lists via Ditto and you have ul/ol/dl elements outside the Ditto results you get a validation error if the result is empty.

              In this case the tplFirst and tplLast should be the better way ... but: if the result is a single list item you’ll missing closing list element. For that an alternate "tplIfSingle" would be helpful.
              • Then a TV is just what you need. It can be edited per-document.
                  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
                  • 24495
                  • 407 Posts
                  Nope, because I have a page where the ditto results change depending on a date. Sometimes I have multiple list items, sometimes there is a single result and sometimes the result is empty. Therefore I created a solution what is not the best but works for me. You can see the real life example at: cms08.fct.de/en/services/training.html (development state, not public this time)

                  The whole "Schedule" list (right column) is a ditto output:
                  [[Ditto? &tpl=`schulungsListing2` &display=`all` &parents=`xxx` &depth=`1` &sortBy=`menuindex` &sortDir=`ASC` &noResults=` `]]


                  The shulungsListing2 is
                  [[schulungLeer? &startId=`[+id+]` &noChild=`` &child=`<h2>[+longtitle+]</h2><ul>`]]
                  [[Ditto? &tpl=`terminListing` &tplLast=`terminListing2` &display=`all` &parents=`[+id+]` &depth=`1` &sortBy=`eventAnfang` &sortDir=`ASC` &language=`german` &noResults=` ` &filter=`eventAnfang,@EVAL return strtotime("+0 day");,6`]]


                  schulungLeer is a modified hasChildren snippet. The leading ul is outside the ditto, the trailing ul is inside the tplLast. This is working for me.
                  • Ah, I see. Yes, you would need a customized snippet to do that.
                      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
                      • 24495
                      • 407 Posts
                      Or we all need an outerTpl for Ditto results that are not empty.