Esteemed monks,
I just ran into an issue with the Template-Toolkit and I'm not sure wether I miss something obvious or if it is a bug in the Toolkit.
On my webserver I have a directory that looks like this:
C:\xampp\htdocs\messages
20050121.html
20050122.html
20050123.html
20050124.html
20050125.html
20050126.html
20050127.html
20050128.html
20050129.html
20050130.html
20050913.html
20051124.html
The names are in the YYYYMMDD-format. In a template I iterate over this directory using
<table cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
[% USE dumper(indent=0, pad="<br>") %]
[% USE dir = Directory('/xampp/htdocs/messages') %]
[% FOREACH file = dir.files.sort %]
<p>[% file.name %]</p>
<p>[%# file.contents %]</p>
[% END %]
</td>
</tr>
</table>
I also tried
[% FOREACH file = dir.files.sort(file.name) %]
[% FOREACH file = dir.files.sort(name) %]
But none of them seems to work, because in the output the files are in this order:
20050128.html
20050127.html
20050126.html
20050125.html
20050124.html
20050123.html
20050122.html
20050121.html
20051124.html
20050913.html
20050130.html
20050129.html
As you can see they are not sorted. Anyone has a clue why?
Yours desperatly,
Update:
I have just noticed that all is well when I just use
[% FOREACH file = dir.files %]
Don't you call that premature optimization? ;(
Anyway the question is still valid. Why does the sort not work?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.