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

    I’m using ModX 1.0.2 and Ditto 2.1.0.
    I have a series of subpages which belong to a parent representing a month of the year e.g

    - February 2010
    -- page 1
    -- page 2
    -- page 3

    - March 2010
    -- page 1
    -- page 2

    and so on.

    I’m trying to create a page which lists all the subpages when the parent page is visited using Ditto.
    For each of the subpages there’s a template variable of type ’date’ with ’widget’ as UNIXTIME, called ’eventdate’.

    My ditto code is:
    [!Ditto? &dateSource=`eventdate` &display=`all` &tpl=`eventitemnew`&dateFormat=`%A %e %B %Y %l:%M%P` &sortDir=`ASC`!]

    And the template content is:
    <div class="item">
    <h4><a href="[~[+id+]~]">[+longtitle+]</a> - [+date+] [+itemcategory1+]</h4>
    <p>[+introtext+]</p>
    <p></p>
    <p><a href="[~[+id+]~]">Click here for more info...</a></p>
    </div>


    All the variables are being displayed fine on the page, and only the correct subpages are being displayed.
    The problem is that the date isn’t being displayed at all no matter what I try.

    The result at the moment is all dates are shown as:
    Thursday 1 January 1970 12:00am

    If I remove the dateSource parameter, and try to show the TV directly using [+eventdate+] (similar to [+itemcategory1+], which does work) then there’s no output.

    Can anyone advise as to what’s going wrong, and if you need any additional info. I’ve spent the last 5 hours trying to figure this out.

    Thanks in advance for all the help.

    EDIT: I guess it’s useful to add, the same thing was working fine on ModX 0.9.6.3 and the problem started after the upgrade - no other changes were made. Also, I’ve tried disabling/enabling phx but it makes no difference.
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      what is `eventdate`?
      if it’s a TV, have try this &dateSource=`[+eventdate+]`?
      Did you or did you not fill the value of [+eventdate+]?
      Thursday 1 January 1970 12:00am is the UNIXTIME first date/time, PHP usually auto-fills the blank DATE value with that.
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 20385
        • 5 Posts
        Thanks for the reply.

        Event date is a TV which is assigned to each of the subpages.
        From reading the Ditto documentation, if assigned as the dateSource then the [+date+] placeholder in the template will refer to this date instead of the publish date.

        If I leave the dateSource as default, and output [+date+] in the template then the correct publish date is displayed, which is expected.
        As soon as I change to eventdate I get the problems.

        I’ve tried your suggestion and it doesn’t work. I guess that was to be expected because at that point [+eventdate+] isn’t declared - it’s assigned to the subpages which need to be displayed by Ditto, not to this parent page which makes the call to Ditto.
          • 11055 ☆ A M B ☆
          • 3,112 Posts
          Have try this?

          <div class="item">
          <h4><a href="[~[+id+]~]">[+longtitle+]</a> - [+eventdate+] [+itemcategory1+]</h4>
          <p>[+introtext+]</p>
          <p></p>
          <p><a href="[~[+id+]~]">Click here for more info...</a></p>
          </div>
            Rico
            Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
            MODx is great, but knowing how to use it well makes it perfect!

            www.virtudraft.com

            Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

            Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

            Maintainter/contributor of Babel

            Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
            • 20385
            • 5 Posts
            Tried that too, and it shows no date at all, not even 1 January 1970.
            It’s as if this TV isn’t being recognised by Ditto even though it exists and was working fine on ModX 0.9.6.3, although the sorting is done correctly if I use that TV to sort the results
              • 20385
              • 5 Posts
              I think I’ve got somewhere with this now, even though my solution might not be the "correct" one.

              I noticed that normally timestamps are stored in the form YYYY-mm-dd H:m:s, but I guess because my site is UK based it was saved as dd-mm-YYYY H:m:s and therefore the date would never go through the date functions properly.

              To solve it I created a custom snippet called stringtodate which converts the old format to a date in my desired format:
              <?php
              if(!$date)
              return false;
              
              if(!$format)
              $format = "l d M Y g:ia";
              
              //mktime: mktime  ([ int $hour = date("H")  [, int $minute = date("i")  [, int $second = date("s")  [, int $month = date("n")  [, int $day = date("j")  [, int $year = date("Y")  [, int $is_dst = -1  ]]]]]]] )
              
              //all dates are stored as 03-06-2010 18:30:00 so we need to convert them to YYYY-mm-dd H:m:s
              $split = explode(" ",$date);
              $splitdate = explode("-",$split[0]);
              $splittime = explode(":",$split[1]);
              return date($format,mktime($splittime[0],$splittime[1],$splittime[2],$splitdate[1],$splitdate[0],$splitdate[2]));
              ?>


              The widget couldn’t be UNIXTIME otherwise it wouldn’t work, selecting the null option did the trick.

              I set a default format, though any valid date() format can be set using a parameter in the snippet call.
              I can output my date using:
              [[stringtodate? &date=`[+eventdate+]` ]]


              Hope this helps someone for now, and maybe there’s a more elegant solution on the way which handles the different date formats correctly.
                • 11055 ☆ A M B ☆
                • 3,112 Posts
                how about your settings in Tools > Configuration > Interface & Features > Date format ?
                  Rico
                  Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                  MODx is great, but knowing how to use it well makes it perfect!

                  www.virtudraft.com

                  Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                  Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                  Maintainter/contributor of Babel

                  Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                  • 20385
                  • 5 Posts
                  It is set to dd-mm-YYYY which makes most sense to the client because they’re UK based. Plus there’s already a LOT of subpages which would need updating to the new date format though I suppose it could be done using a PHP/MySQL script to update all the relevant records.

                  The weird thing is it was working fine on the older ModX version, it’s the upgraded version with problems. I know the old version doesn’t have the option to select the date format, but in the date picker, it does appear as dd-mm-YYYY.
                    • 8790
                    • 526 Posts
                    Hi,

                    I posted something quit the same a few days ago.

                    Have look to it plz. http://modxcms.com/forums/index.php?topic=60384

                    The point is that Ditto does not seams to parse A TV value (except the standard tv or pl coming from modx itself)
                    To use YOUR tv in the Ditto loop, try to use [+tvYourTvName+] in the call instead of [*YourTvName*]

                      Schtroumpf Grognon - Grouchy Smurf
                      ---------------------------------
                      Faites pas attention.. - Don&#39;t pay attention
                      http://www.dzi-neo.net