We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19726
    • 239 Posts
    Hi, I am trying to build a table with Ditto (using RC3 in this case). The table should just list pagetitles of documents in column 1and 2 tvs in column 2 and 3. I tried to do this by providing Ditto with 3 templates.

    -- tplFirst --
    <table>
    <tr><td>[+pagetitle+]</td><td>[+tv1+]</td><td>[+tv2+]</td></tr>
    -- tpl --
    <tr><td>[+pagetitle+]</td><td>[+tv1+]</td><td>[+tv2+]</td></tr>
    -- tplLast --
    <tr><td>[+pagetitle+]</td><td>[+tv1+]</td><td>[+tv2+]</td></tr>
    </table>


    This works just fine except when there is only 1 item in the list, because then only the "tpl" template is used, so I am missing the <table> tags. Is there a way to make a table in this way with Ditto, or should I find a complete other way (hints appreciated wink ) ?

    BTW the list of documents can also be empty so I can’t just add the <table> tags to the template and put the Ditto call in between.
      • 18397
      • 3,250 Posts
      Use Ditto 2 (RC3 until Thursday) and create a config file with
      $header="<table>"; 
      $footer="</table>";
      

      Then add &config=`configName`to your Ditto call and volia!
        • 11975
        • 2,542 Posts
        Hi,

        I’m not certain if these params will be in the final version of ditto 2

        Open the formats/html.format.inc.php

        and add
        $header="<table>";
        $footer="</table>";

        Then edit the snippet code of ditto

        around line 941

        Change

        $output = $header.$noResults.$footer;

        to

        $output = $noResults;

        That should do the trick

        :-)

        Edit: Mark has been faster than me


        EDIT 2: To readers follow the Mark advice and do not edit the format file

          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 19726
          • 239 Posts
          Very nice, thanks for the fast reply. I was already wondering what the &config parameter would do grin

          Note that the exact text to put in the config file is as below (so including the php tags)
          <?php
          $header="<table>"; 
          $footer="</table>";
          ?>
            • 19726
            • 239 Posts
            Just a small notE on this. It works fine for the case when there is 1 or more documents. It also is a lot easier to maintain (I don’t have to keep tplFirst and tplLast), but when the list is empty I now get
            <table><p>No documents found.</p></table>
            . For now I just changed the no documents message to "<tr><td>No documents found</td></tr>" which at least is valid code, but I was wondering if there is a way to not have the header and footer when there are no results?
              • 11975
              • 2,542 Posts
              Then edit the snippet code of ditto

              around line 941

              Change

              $output = $header.$noResults.$footer;

              to

              $output = $noResults;

              That should do the trick

              :-)

              :-)

              EDIT: these changes won’t be enough in fact

              If the determineIDs function has results the output will have the header and footer added anyway
                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 28865
                • 39 Posts
                Hey Guys sorry my English is not so good.

                Hey, I would like to implement Ditto

                Pagination

                table header
                table row > Item1 > Item2
                table row > Item3 > Item4
                ..
                table End

                Pagintation

                Only Ditto may not differ when the 2nd item.
                Because danch he must indeed close the series, and then the new fixation.

                How could I fix it?
                  WebHosting 100% Zen-Cart, Joomla, MODx, SMF kompatibel. !!kein SafeMode Problem!! http://www.Sunny-Host.de
                  CodeSnippes und Erfahrungen zu Zen-Cart, MODx & Joomla http://blog.Sunny-Host.de
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  You could try getting the same effect with floated divs. Create a container div the width of the "table", then have the Ditto template create divs and in your CSS have them be set to a width of about half of your container’s width, a specified height, and floated left. That way it will float two per row and drop the next set of two down to the next row.

                  If you really want tables, start it like this:
                  <table><tr>
                  [[Ditto? ... &tpl=`dittoTpl` &tplAlt=`dittoTplAlt` ... ]]
                  </table>
                  

                  Then have your tpl chunk
                  <td>[+whatever-placeholder+]</td>

                  then your tplAlt chunk
                  <td>[+same-placeholder+]</td></tr><tr>

                  If you don’t have an even number of items it will not have the final </tr> but it should work anyway; it just won’t validate in that case. You could also put the last </tr> after the snippet call, along with the closing </table> tags, and in that case you’d have duplicate </tr> tags if you do have an even number. Again, it should still work, it just won’t validate. You might be able to use phx somehow to work this out.
                    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
                    • 28865
                    • 39 Posts

                    So, I have it at the time, only the content is not always the same high, and with tables, I have it better because under control. Currently there with a big confused Divs
                      WebHosting 100% Zen-Cart, Joomla, MODx, SMF kompatibel. !!kein SafeMode Problem!! http://www.Sunny-Host.de
                      CodeSnippes und Erfahrungen zu Zen-Cart, MODx & Joomla http://blog.Sunny-Host.de
                      • 28865
                      • 39 Posts
                      Super thats OK grin grin
                        WebHosting 100% Zen-Cart, Joomla, MODx, SMF kompatibel. !!kein SafeMode Problem!! http://www.Sunny-Host.de
                        CodeSnippes und Erfahrungen zu Zen-Cart, MODx & Joomla http://blog.Sunny-Host.de