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.
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.
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.
What is your DateTime snippet code ?
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.
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? ×tamp=`1104037200`]] I get the correctly formatted human-readable date back of 12/26/2004. When I leave the value empty — ×tamp=`` — 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.
-
☆ 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.