Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:
Continuing the project I started with quite some time ago and just completing recently (for the regular definition of "completed" - i.e., release early release often), I've decided to make my front page a bit more dynamic. So I started by doing some simple stuff. For example, our group's meeting dates are already in a CSV table, so I just created a function in my plugin that extracted it from a table with "YEAR,MONTH,DAY,..." as the first column headers, converted it to something readable ("Monday, May 8, 2006"), et voila, I got what I wanted. Plop it into a cron entry, which both runs ttree and a small ftp upload script I also have, and it's about as dynamic as it needs to be.
The next step was to put descriptions of upcoming events. However, I'm figuring that I don't need to continue advertising upcoming events after they passed. So a bit more magic, and I came up with this:
and then ...[%- USE date %] [%- SET today = date.format(date.now, "%Y%m%d") %]
The only minor annoyance is that my editor of choice seems to think that the < sign there is the open character for an HTML tag. But that's really quite minor.[% IF today < 20060406 %] <p>Guess what. On April 6, 2006, we're going to do something special! On April 7th, this paragraph disappears! Neat!</p> [% END %]
What I'm wondering is if anyone can see, or better yet, already uses, a more elegant solution. Perhaps a filter? Is there such a beast built in that I'm missing? Or perhaps that I haven't figured out the right keywords for searching on CPAN? I imagine this would be easy for TT2 experts, but I'm just not seeing it today for some reason.
By "elegant" I mean a few things. First, the template must be readable. Putting in unix timestamps (seconds since epoch) isn't readable ;-). Second, it should be able to handle both begin and end dates. So I may not want to start displaying some text until a certain date, and/or I may want to stop displaying some text after a certain date. The simple numeric comparison above meets that through simple numeric comparisons. However, a bit more obvious to me would be something like:
Obviously, since this is a static document, I'll have to ensure the cron job gets run daily at an appropriate time. But that's somewhat outside the scope of my question.[% FILTER ByDate start = '2006-04-15' until = '2006-06-28' %] This is only visible from April 15 through June 28, 2006. [% END %]
Is this reasonable/normal usage of TT2? Is there something I'm overlooking?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Date-sensitive output with Template Toolkit
by merlyn (Sage) on Apr 05, 2006 at 02:32 UTC | |
|
Re: Date-sensitive output with Template Toolkit
by perrin (Chancellor) on Apr 05, 2006 at 04:19 UTC | |
|
Re: Date-sensitive output with Template Toolkit
by CountZero (Bishop) on Apr 05, 2006 at 06:28 UTC | |
|
Re: Date-sensitive output with Template Toolkit
by nferraz (Monk) on Apr 05, 2006 at 09:53 UTC | |
|
Re: Date-sensitive output with Template Toolkit
by Herkum (Parson) on Apr 05, 2006 at 13:07 UTC | |
|
Re: Date-sensitive output with Template Toolkit
by amw1 (Friar) on Apr 05, 2006 at 20:32 UTC | |
by Clachair (Acolyte) on Apr 06, 2006 at 00:06 UTC |