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

    Question #1: I’m betting this is a matter of a simple snippet, but I’m not quite experienced enough to come up with the solution. I’ve got a custom date TV set up for news articles, using the unixtime widget, which seems to be necessary in order for ditto to use the custom date TV. I can easily manipulate the date format with &dateFormat in the summary page (from which the ditto call is made), but on individual article pages, the date is unixtime format. I just need a nudge on how to reformat that string to a human-readable time.

    Question #2: Is there already a mechanism by which one could re-order a listing’s output by another field, and to change the sort direction? For instance, my ditto tpl outputs news summaries to a table with the following columns: date, news outlet, author, and article title. What I’d like to do is provide clickable column headings, allowing end-users to change how the table is sorted. Any ideas?

    Eagerly awaiting your thoughts ...
      ------
      Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
      • 7231
      • 4,205 Posts
      1) use the date TV as the &datesource and in the tpl use [+date+] to place the date. It will be in the same format as the way you formated it in ditto. Alternatly you could use the dateTime snippet to format the date TV directly in the tpl.

      2) I dont think that there is a redy made solution for this, but Ditto has a few built in features that will allow you to set a custom sort based on a url parameter. So you can have an action link that would send a parameter in a url and then use this to set the sortBy. I have never done this but it can be done. Maybe someone with actual experience can help. Check out the Ditto support site http://ditto.modxcms.com/ for all of the available options. I think it is the request extender that does this.

      You could also build a simple snippet to get the parameter from the url and apply it to Ditto. This would be my approach since this is straight forward.
        [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]
        • 27733
        • 99 Posts
        Thanks for your suggestions! On #1, however, I’m in a pickle. Here’s exactly what I’ve got:

        My TV for article dates is [*articleDate*] and is using unixtime widget ... My ditto call is—
        [!Ditto?parents=`522` &depth=`0` &sortBy=`articleDate` &dateSource=`articleDate` &tpl=`articleTbl` &display=`100`]]


        My articleTbl tpl is—
        <tr>
          <td>[+articleDate:date=`%m/%d/%Y`+]</td>
          <td>[+articleSource+]</td>
          <td>[+article-auth-ln+], [+article-auth-fn+]</td>
          <td><a href="[~[+id+]~]">[+articleTitle+]</a></td>
        </tr>
        


        Up to here operates as expected. It’s once you head to the full page itself that trouble occurs. Here is the header template for full pages—
        <h2>Article Library</h2>
        <p><a href="[~499~]" title="Return to Article Index">< Return to Article Index</a></p>
        <p>Source: [*articleSURL*]<br />
        Author(s): [*article-auth-fn*] [*article-auth-ln*]<br />
        Date: [[GetTime? &usedDate=`articleDate`]]
        </p>
        <h3 class="articles">[*articleTitle*]</h3>
        [*content*]
        


        The resulting date for every one of these full pages is coming up 12/31/1969. Any idea why this is happening?

        Thanks for taking another look!
          ------
          Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
          • 36592
          • 970 Posts
           [[GetTime? &usedDate=`articleDate`]] 

          I doubt if GetTime snippet support TV as parameter &usedDate ...
            • 7231
            • 4,205 Posts
            Try using the dateTime snippet. It supports unix time stamp as the input value.
            http://www.modxcms.com/DateTime-884.html
              [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&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 27733
              • 99 Posts
              Unfortunately, same deal with DateTime — outputting 12/31/1969.
              Here are a few examples the correctly-formatted dates and the date strings output via the TV on the final pages (without using the DateTime snippet):

              [table]
              [tr]
              [td]Output from ditto[/td]
              [td] | [/td]
              [td]Output directly
              from the TV
              [/td]
              [/tr]
              [tr]
              [td]12/26/2004 00:00:00[/td]
              [td] | [/td]
              [td]1104037200[/td]
              [/tr]
              [tr]
              [td]09/15/2004 00:00:00[/td]
              [td] | [/td]
              [td]1095220800[/td]
              [/tr]
              [tr]
              [td]04/01/2004 00:00:00[/td]
              [td] | [/td]
              [td]1080795600[/td]
              [/tr]
              [/table]

              I’m guessing that whatever code makes the conversion in ditto is what I need. Any clues?
                ------
                Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
                • 36592
                • 970 Posts
                What is your DateTime snippet code ?
                  • 27733
                  • 99 Posts
                  The code is:

                  <?php
                  /**
                   * DateTime 
                   * Makes a date and time... thingy. Now even thingier.
                   * Original author Alex Butter.
                   * 1.02 amended 08Aug06 by Paul Gregory, inspired by doze & breezer.
                   * 1.03 by Aramaki 27 Jan 2008
                   */
                  if(!isset($format)) {
                      $format="%d-%m-%Y %H:%M:%S";
                  }
                  if(!isset($timestamp)) {
                      $timestamp=time();
                  }
                  if(!isset($shift)) {
                      $shift=0;
                  }
                  return strftime($format, $timestamp+$shift+$modx->config['server_offset_time']);
                  ?>
                  
                    ------
                    Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
                    • 27733
                    • 99 Posts
                    OK, so after a little experimentation, it seems the problem may lie in getting the timestamp itself. Keep in mind this timestamp is generated by a TV I created: [*articleDate*]. When I input a timestamp directly using, for instance, [[DateTime? &timestamp=`1104037200`]] I get the correctly formatted human-readable date back of 12/26/2004. When I leave the value empty — &timestamp=`` — I get the dreaded 12/31/1969, which is epoch time minus the 5-hour offset (as I’m EST).

                    So, how do ya grab a value from a TV that’s in the tv table and not in the content table?
                      ------
                      Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      If you are trying to format the value of the TV as if it were a timestamp and are using the TV’s date/time widget, your formatting code will choke because the TV widget is not returning a timestamp, but a pre-formatted date/time string. If you want to format the timestamp yourself, don’t use an output widget at all.
                        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