To share the code, just make it an attachment...
just gzip it first... that way we can do a 'diff' to see what is
different.
I am familiar with the 'paging' problem... I
created a paging module specifically to handle the ability to paginate arrarys
that would be used within a H::T page. It also required to know the length
of the array it was going to paginate - which is not too much of a problem,
since if you want to show items 50 to 60 of a 100 item list, you need the length
of the list so that you can figure out how many pages in total there
are.
Attached is a snapshot of the output of my table
paginator. This paginator remembers how you viewed the page the last time
(as in 'show all' mode, and the 'rows per page'), which is a really nice feature
to have - as such, I'm not sure you could implement this capability purely in
the H:T since it requires some form of backing-store to save the per-user
information. ... Although, I could be wrong...
As for using H::T::E... try something like
this:
<table width=100% border=0 cellpadding=1
cellspacing=1> <TMPL_LOOP
gallery>
<TMPL_IF EXPR="(__counter__ % 3) ==
1">
<tr
valign=top>
</TMPL_IF>
<td width=33% align=center valign=top
class=text>
<TMPL_VAR
NAME=description>
</td>
<TMPL_IF EXPR="(__counter__ % 3) ==
0">
</tr>
<tr>
<td
colspan=3>
</td>
</tr>
</TMPL_IF>
</TMPL_LOOP> </table>
This will give you a table with 3 columns + however
many rows it takes to display all your TMPL_LOOP rows.
The main disadvantage to this is that it needs to
evaluate the expressions at runtime, not at template parsing time... However, in
my experience, the use of expressions within the templates is a very small
component of the time it takes to serve the page -> most of the time is spent
generating the page data, not generating the page output.
Mathew
----- Original Message -----
Sent: Thursday, October 07, 2004 11:36
AM
Subject: Re: [htmltmpl] MARK= enhancement
to the HTML::Template LOOP construct
I'd be happy to share the code -- just tell me how. However, it's
not all that complex. I just hacked in some more context variables to be
set during a TMPL_LOOP's output. The only trick (?) is to parse and
stashing the MARK value in the TMPL_LOOP object.
I had the same thought as you initially -- why make TMPL_LOOP
iterate over items if you know you're only gonna use the first three, for
example. However, I found there's some mileage to be gained by iterating
all the items and only tagging (mark-ing) the ones you declare an interest
in. It gave me the ability to take an arbitrarily long list and
layout the first 6 items, and know whether or not it makes sense to
show 6 real items, or 5 items and a "MORE" link. I
couldn't do that if I just iterated the first 6 items because there's no way
to test against the number of items in the loop. However, by iterating
all the items, I can detect the __LAST__ one and check to see if it's been
__MARK__ed. If not, then I know there's at least one item beyond the
ones a laid out, and I need to show "MORE".
I'd like to know more about how you use H::T::Expr. Maybe I just
didn't get it, but I couldn't see any way for it to interact with my
<TMPL_VAR> values. For example: I wanted it to test the value
of the current TMPL_LOOP's __COUNTER__, but it just didn't seem to work
that way. Did I miss something?
What sorts of custom TMPL_xxx tags do you create?
Mathew Robertson
<[EMAIL PROTECTED]> wrote:
My local copy of H::T is modified so that a)
you can create custom TMPL_xxx tags, and b) you can create custom ESCAPE
tags by overloading a H::T::Escape (I have factured out that
functionality into seperate modules).
I'd be interested to how you did this MARK
stuff - I have previously used H::T::Expr to generate custom layouts,
although I consider this solution to be rather hack'ish since I tend to
think that TMPL_LOOP's need not always loop from start to finish of
Perl array.
regards, Mathew
----- Original Message -----
Sent: Wednesday, October 06, 2004
10:31 PM
Subject: [htmltmpl] MARK= enhancement
to the HTML::Template LOOP construct
Greetings everyone! I've been using HTML::Template on my site
for several years now, and I'm really pleased with what it can do and how
easy it is to teach my HTML'ers. I'd like to share
with you some enhancements I've done to make it even more powerful
(for me, at least).
I make heavy use of the <TMPL_LOOP> tag on my site.
However, I seem to always want to do something that's hard. For
example, I want to layout the loop items in three columns (instead of two
using the __ODD__ tag). Or, I want to layout just the first 5 items
and (if there are more) make a link to "see more". Or, I
want to lay items in 4 balanced columns (i.e. A-G arranged vertically in
the first column, H-N in the second, O-U in the third, V-Z in the
last).
To accomplish this, I implemented a "MARK=some-value" tag for the
<TMPL_LOOP> construct. This MARK tag requests that the
additional loop context variables __MARK__, __MARKFIRST__, and
__MARKLAST__ be set. There are four possible formats for the MARK
value.
If I say "MARK=3" then the first item and every third item thereafter
will have __MARK__ set to true (i.e. it will be true for items 1, 4, 7,
10, etc.). __MARKFIRST__ is set true whenever __MARK__ is true, and
__MARKLAST__ is set true for the last item before __MARK__ is true (i.e.
items 3, 6, 9, etc.). With this I can easily setup N-column displays
in HTML by triggering my <TR> starts and ends with __MARKFIRST__ and
__MARKLAST__.
If I say "MARK=-6" then all the items before item 6 (items 1 through
5) will be __MARK__'ed true. The first item will be __MARKFIRST__,
and the 5th item (or the last item if there are less than 6 items) will be
__MARKLAST__. This helps me process a list of items when I just want
to show the first N, but want to be smart enough to know if there are more
items to talk about. Since the <TMPL_LOOP> iterates over all
the items, I can trap the __LAST__ item and check to see if it was
__MARK__'ed. If so, I can offer a "more" link.
Of course, there's a complimentary "MARK=+5" option to mark the items
that occur after item 5 (items 6 on).
Finally, the hardest thing to do is layout balanced columns. To
do this I specify "MARK=TOTGRP/GRP", as in "MARK=3/2". This tells
the loop to divide the items in to TOTGRP balanced groupings (three in
this case), and __MARK__ the items in the GRP grouping (two in this
case). For example: I often have a list of alphabetized names, and I
want to show them in a way that people are used to, which is to have them
vertically alphabetized, and split into N balanced columns. Using
this tag my HTML becomes something like this:
<TABLE><TR VALIGN="TOP">
<TD>
<TMPL_LOOP NAME="foo" MARK="3/1">
<TMPL_IF __MARK__> output an item in column
1<BR></TMPL_IF>
</TMPL_LOOP>
</TD>
<TD>
<TMPL_LOOP NAME="foo" MARK="3/2">
<TMPL_IF __MARK__> output an item in column 2
<BR></TMPL_IF>
</TMPL_LOOP>
</TD>
<TD>
<TMPL_LOOP NAME="foo" MARK="3/3">
<TMPL_IF __MARK__> output an item in column 3
<BR></TMPL_IF>
</TMPL_LOOP>
</TD>
</TR></TABLE>
I've found these enhancements to be very useful, as they save me from
coding layout decision flags in my loop items, while enabling more
sophisticated layout possibilities.
Comments? Thoughts? Suggestions? It works for me --
would it work for anyone else?
-Bob Diss
Do you Yahoo!? vote.yahoo.com -
Register online to vote today!
Do you Yahoo!? vote.yahoo.com -
Register online to vote today!
|