Gossamer Forum
Home : Products : Gossamer Links : Pre Sales :

New Template Module.

Quote Reply
New Template Module.
Hi,

We've rewritten the template module, and internal tests now show it to be around 2.5 times faster in parsing templates. The good news now is the new features we support:

1. else tags:
<%if foo%>
..
<%else%>
..
<%endif%>

2. elsif tags:
<%if foo%>
..
<%elsif bar%>
..
<%else%>
..
<%endif%>

3. include's that include any file (sorry Robert). =)

<%include /www/styles.css%>

4. print as you parse:

GT::Template->parse ('filename', { foo => bar }, { print => 1 });

will now parse the template and print it out as it goes.

5. Loop support! This is the big one.

<%loop link_results%>
<p> <%include link.html%>
<%endloop%>

would go through your link results, and print <P> followed by the link.html template. Also, inside your loop you have the following tags automatically available:

<%row_num%> - a counter for what row is being looped, starts at 1.
<%first%> - boolean that is true if this is the first row, false otherwise.
<%last%> - boolean that is true if this is the last row, false otherwise.
<%inner%> - boolean that is true if this is not first and not last.
<%even%> - boolean is true if row_num is even.
<%odd%> - boolean is true if row_num is odd.

You can use even and odd tags to produce alternating colors like:

<%loop results%>
<tr><td bgcolor="<%if even%>#FFFFFF<%else%>#000000<%endif%>">..</td></tr>
<%endloop%>

From a programming side of things, it's very easy to specify loops. You just pass in an array of hashes, or a code ref. So:

my $sth = $db->select ( { Status => "Administrator" });
GT::Template->parse ('template', { admin_loop => sub { $sth->fetchrow_hashref });

And then in your template you would do:

Your administrators are:
<%loop admin_loop%>
User: <%Username%>
Pass: <%Password%>
<%endloop%>

Let me know what you think on syntax, etc.

Cheers,

Alex

--
Gossamer Threads Inc.
Subject Author Views Date
Thread New Template Module. Alex 6130 Feb 5, 2001, 1:53 PM
Thread Re: New Template Module.
Robert_B 6040 Feb 5, 2001, 2:44 PM
Thread Re: New Template Module.
Alex 6007 Feb 5, 2001, 2:58 PM
Post Re: New Template Module.
Robert_B 5966 Feb 5, 2001, 3:12 PM
Thread Re: New Template Module.
Paul 5942 Feb 6, 2001, 10:29 AM
Thread Re: New Template Module.
Alex 5944 Feb 6, 2001, 10:57 AM
Post Re: New Template Module.
Paul 5941 Feb 6, 2001, 11:03 AM
Post Re: New Template Module.
Paul 5951 Feb 6, 2001, 11:05 AM
Post Re: New Template Module.
Lance Rasmussen 5991 Feb 5, 2001, 2:50 PM