Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Proper template parser syntax?

Quote Reply
Proper template parser syntax?
Hi all,

I'm trying to optimise the following code that is currently WORKING but seems a bit clunky to me:

<%-- Begin Featured Loop --%>
<%loop links_loop%>
<%if Overview_Status eq Featured %>
<tr><td>&nbsp;</td></tr>
<tr><td bgcolor="eeeeee">Featured</td>
</tr>
<%lastloop%>
<%endif%>
<%endloop%>

<%loop links_loop%>
<%if Overview_Status eq Featured %>
<tr><td>
<%include link.html%>
</td></tr>
<%endif%>
<%endloop%>
<%-- End Featured Loop --%>

Basically I'm trying to parse a bunch of links into "buckets". First, I want to loop through the set of links and see if there are any links in a particular bucket, in this example the bucket is "Featured". Then, if there is a "Featured" link, I want to go back through the array and pull ALL of the links in that bucket and place them under the "Featured" header.

Thanks to any of you template gurus out there that can help me.

Mike
Quote Reply
Re: [Swaylock] Proper template parser syntax? In reply to
Hi,

I can't think of an easier way off hand, you would need to use a template global. Something like:

Code:
featured_links =>
sub {
my $tags = GT::Template->tags;
my @featured;
foreach $link (@{$tags->{links_loop}}) {
if ($link->{Overview_Status} eq 'Featured') {
push @featured, $link;
}
}
return { featured_loop => \@featured, featured_count => ($#featured + 1) };
}

and then do:

<%featured_links%>
<%if featured_count%>
display header
<%endif%>

<%loop featured_loop%>
display link
<%endloop%>

display regular links.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Proper template parser syntax? In reply to
Thanks Alex. I'm looking into it.
And thanks for excellent products.
Regards,
Mike