We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    It was probably written for NewsListing, Ditto’s predecessor. If I recall, the basic idea was to save the current time if no value was set to the tv using a plugin.
      • 275
      • 12 Posts
      I followed the tutorial found at http://ditto.modxcms.com/tutorials/sort-by-a-date-tv.html and everything is working great BUT if the client doesn’t enter a date to the template variable [*myDate*] then the date for the blog entry is shown as December 31, 1969. Is there a way to set up the Ditto call so that if no specific date source is given in [*myDate*] that it will automatically use the published date instead? Or is there some setting I’m missing in the template variable itself?

      Here is what I have on the main blog listing page (found at http://www.ivsod.com/blog)

      [tt][!Ditto? &startID=`30` &summarize=`5` &total=`50` &tpl=`basicBlog` &paginate=`1` &paginateAlwaysShowLinks= `1` &sortBy=`myDate` &sortDir=`DESC` &dateSource=`myDate` &dateFormat=`%b %e, %Y` &tagData=`blogTags` &tagDelimiter=`,` &tagDisplayDelimiter=`, ` &tagSort=`0` &tagDocumentID=`36` &tagMode=`onlyTags` &filter=`id,36,2|id,35,2`!]

      <div class="pagination"><p>Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles | Page <strong>[+currentPage+]</strong> of <strong>[+totalPages+]</strong> </p> <div id="ditto_pages"> [+previous+] [+pages+] [+next+] </div></div> [/tt]

      __
      I’ve managed to figure most of this out but I just can’t seem to figure out this last little piece. I appreciate any help that might be offered.
        • 36592
        • 970 Posts
        Quote from: abdowling at Oct 09, 2009, 11:57 AM

        Is there a way to set up the Ditto call so that if no specific date source is given in [*myDate*] that it will automatically use the published date instead?
        I’ve never tried this but doesn’t just using Default Value for myDate TV work ?
          • 275
          • 12 Posts

          I’ve never tried this but doesn’t just using Default Value for myDate TV work ?

          I’d considered that possibility but had no idea what to put in the Default Value area so that the published date would show up.
            • 36592
            • 970 Posts
            [*publishedon*] ?
              • 275
              • 12 Posts
              Quote from: tkfm at Oct 10, 2009, 02:12 PM

              [*publishedon*] ?

              No such luck. I tried that and [*createdon*] in the Default Value of my [*myDate*] template variable and neither shows anything but December 31, 1969.
                • 275
                • 12 Posts
                So any takers on this one?

                Recap.... have template variable set up to allow for custom date with ditto but if client doesn’t bother entering in a specific date then December 31, 1969 is shown as default date. Goal - if the client enters nothing in template variable then ditto simply defaults to published date. See previous replies above to see what I’ve tried so far.

                I’m stumped on this one.

                I just *know* someone has got a similar set-up working somewhere. There has to be. Thanks in advance for any help!
                  • 11681
                  • 98 Posts
                  Has something changed since the last post on this thread, abdowling’s of 22-Oct-2009? I am not able to duplicate success in using Ditto to order by a user-supplied date in a template variable.

                  I am using MODx 1.0.3 with no modifications to its Elements as supplied.

                  No problem ordering using the createdon document variable. Also, no problem defining the template variable and connecting it to the document instances: I can Preview each document to observe both createdon and TV values as unixtime long integers.

                  When I use this Ditto call
                  [!Ditto?
                    &debug=`0`
                    &parents=`[*id*]`
                    &display=`4`
                    &start=`1`
                    &showPublishedOnly=`0`
                    &orderBy=`myDate DESC`
                    &dateSource=`myDate`
                    &dateFormat=`%c`
                    &tpl=`departmentMainTpl`
                    &paginate=`1`
                    &paginateAlwaysShowLinks=`0`
                  !]

                  I get this error
                  « MODx Parse Error »
                  MODx encountered the following error while attempting to parse the requested resource:
                  « PHP Parse Error »
                   
                  PHP error debug
                    Error: 	strftime() expects parameter 2 to be long, array given	 
                    Error type/ Nr.: 	Warning - 2	 
                    File: 	/home1/gopgroto/public_html/assets/snippets/ditto/classes/ditto.class.inc.php	 
                    Line: 	294	 
                    Line 294 source: 	$placeholders['date'] = strftime($dateFormat,$timestamp); 

                  If I remove the &dateSource parameter, the page renders without error, but of course the intended document ordering does not happen.

                  Please advise if I’ve missed something, if using Ditto with a user-supplied date is done differently now, or if this is a bug. If the latter, is there a workaround?

                  BTW, my end goal is the same as abdowling and a few others have stated: To order on a user-supplied date, but to revert to some reasonable alternative, such as createdon or publishedon, when the user neglects to supply a date. This would allow the user to construct a decent list of future events, then put it into calendar order with a little extra work if necessary. That’s the behavior we’re trying to achieve.

                  For now, I’d settle for just ordering on myDate successfully.

                  Thanks in advance for ideas.
                    I looked just like that in 1964.
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    It expects your MyDate TV to be a UNIX timestamp. For it to do that, you have to use a "unixtime" output widget.
                      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
                      • 11681
                      • 98 Posts
                      Indeed, I do use the Unixtime widget. To confirm that the widget works as intended, I added HTML to the document template (to which the myDate TV is bound) in order to compare the widget’s output with the createdon document variable: I know that createdon is in appropriate format because it supports document ordering. This allows Previewing each document and examining myDate and createdon side by side. Both appear as long integers of roughly the same value, as would be expected.

                      The error complains that an array is being passed to strftime() in the guise of $timestamp, rather than the single long integer the function expects. The error happens when I include the &dateSource parameter in the Ditto call; it does not happen when I remove that parameter. Why that is so and how to remedy it is my question.
                        I looked just like that in 1964.