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.
Quote Reply
Re: New Template Module. In reply to
Are these features included with the current 2.0.0 version?

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: New Template Module. In reply to
They sound great to me Alex. And a lot more powerful!

Lance Rasmussen
Bowlingzone.com

Quote Reply
Re: New Template Module. In reply to
No, but they will be in the update I put up later tonight.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: New Template Module. In reply to
Will it be possible to install only the files which have been changed since the 2.0.0 release?

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: New Template Module. In reply to
That is excellent....

In Reply To:
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%>
So basically the code above selects the status table, then admin_loop just keeps the query going until no more administrators can be found?



Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: New Template Module. In reply to
Exactly, except it's the Users table (which I think is what you meant). =)

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: New Template Module. In reply to
*a-hem*......yes must have lost my concentration for a minute...Smile

I've not looked at the tables much so the names escape me :)

Please respect my new authority. Smile

....that is a joke by the way before I get tons of complaints!



Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: New Template Module. In reply to
Ok...whilst we are on the point...the code you supplied doesn't mention the Users table anywhere so how does it know which table you want to look in?

Paul Wilson.
new - http://www.wiredon.net