Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Solution for 3 column links

Quote Reply
Solution for 3 column links
hi,

i've come up with a solution to display links in 3 columns - it's a minor tweak of the code in the link below for 2 columns...

See this thread for the 2 colum code

if someone can have a look at the global i've made and show me how to extract the html back out into the template it would be great! it would be a lot tidier if it returned a either true / false and the html was selected in the template.

here's how I did it anyway...

1. make a global called "finishcolumns"

Code:
sub {

my $num = $_[0];

$num++;

if ( $num % 3 ) {
return "<TD width=\"200\">&nbsp;</TD><TD width=\"200\">&nbsp;</TD>";
} else {
return "<TD width=\"200\">&nbsp;</TD>";
}


}

2. replace the code below in the 2 column mod...

Code:
<%if row_num % 2 eq 1%> <%-- balance the trailing rows --%>
<TD></TD><TD></TD>
<%endif%>

with this...

Code:
<%finishcolumns($row_num)%>

and you're done.


let me know if anyone can see a way to make it better.

cheers,
regan.
Quote Reply
Re: [ryel01] Solution for 3 column links In reply to
Just a minor alteration...in the return statement you could change the first " to q| and the last to |; to save escaping the other "'s and you could use "x 2" ...eg

if ( $num % 3 ) {
return q|<TD width="200">&nbsp;</TD>| x 2;
} else {
return q|<TD width="200">&nbsp;</TD>|;
}

Last edited by:

Paul: Jun 14, 2002, 4:36 PM
Quote Reply
Re: [Paul] Solution for 3 column links In reply to
In Reply To:
Just a minor alteration...in the return statement you could change the first " to q| and the last to |; to save escaping the other "'s and you could use "x 2" ...eg

if ( $num % 3 ) {
return q|<TD width="200">&nbsp;</TD>| x 2;
} else {
return q|<TD width="200">&nbsp;</TD>|;
}


Cool - I'll change that now.

Can you see a way to change it so the html is in the template instead of the global? So it's something like...

Code:
<%if finishcolumns($row_num)%>
DISPLAY 2 COL HTML
<%else%>
DISPLAY 1 COL HTML
<%endif%>

I can't seem to get it working right when i try it.

regan.
Quote Reply
Re: [ryel01] Solution for 3 column links In reply to
You could try something like:

return $num % 3 ? 1 : 0;

Then your if/else should work.