Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Alternating Row Color

(Page 1 of 2)
> >
Quote Reply
Alternating Row Color
I don't know if what I'm trying to do is possible but I'll toss it out here to the collective minds..

What I'm trying to accomplish is to get the rows of links to alternate colors similar to green-bar paper and for those not old enough to remember what that is Wink, the main index of the forum here.

Basically when you are at the main category page I click on a category and in that following page I'd like to have the rows alternate color. I've been modifying the link.html template to get everything structured the way I want it on each row and this color issue has got me stumped..

Thanks
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
There should be examples in the LSQL docs. Check it.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Alternating Row Color In reply to
After two days of working on this a lightbulb went on and I told myself "RTFM like you tell everyone else to do" Shocked.

I have gone through all 135pages of the Links SQL Version 2.2.0 manual a couple times but it's quite possible that I'm still missing something..

Is that the doc you are referring to and if so, what have I missed?
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
if you're using a loop for your link results, then <%odd%> and <%even%> tags are automaticly included for you to use. Check the documentation for GT::Template for further details.

Philip
------------------
Limecat is not pleased.

Last edited by:

fuzzy logic: Mar 16, 2005, 7:45 AM
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
Hmm, I thought this got included into the PDF doc, too.
Maybe GT should include the template tutorial into PDF doc, too...

Here you can get the solution in GT::Template doc:
http://www.gossamer-threads.com/...ic=/GT/Template.html

Check the "Loops" part.
There says: "You could use even and odd tags to produce alternating colors like:".
There is an example how to do that...

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [fuzzy logic] Alternating Row Color In reply to
Hmm. It seems, you was quicker than me.
I didn't see your answer.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
Ah, sorry. I forgot, that it's a password protected page.
Working link is the following:
http://admin:admin@www.gossamer-threads.com/...html#template_syntax

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Mar 16, 2005, 8:03 AM
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
If that still doesn't help you (as you write in email), go to your admin interface and click Help on top right of Admin page.
You get the same help pages there inside the GT Module Documentation/GT::Template module.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Alternating Row Color In reply to
Has anyone suggested;

Code:
<%if odd%>bgcolor=red<%else%>bgcolor=blue<%endif%>

Smile

Edit: I see someone has already suggested this. I'll leave my post here anyway <G>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Mar 16, 2005, 8:40 AM
Quote Reply
Re: [Andy] Alternating Row Color In reply to
Eh, I directly not pasted the code here, just a reference to the docs.
I want people to have forced a bit, to check the docs first, before they ask on the forum...
You might follow that way, too...

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [Andy] Alternating Row Color In reply to
Andy are you saying in GT we change the link_results (where)?

sub {
my $vals = shift;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC');
my $sth = $link_db->select;
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}



Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [webmaster33] Alternating Row Color In reply to
webmaster33,

Not to be rude - but after reading those doc - 100 different ways and eyes getting crossed - hitting the forum is the next step - not always the first step. Tony chatted with me about the issue and came here for assistance.

Coming here should not be a lesson in how much have you suffered first before asking a question.

I hope someone can assist in this matter.


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Alternating Row Color In reply to
no, if you are already using the results loop, you do not need to make any changes, except to add the odd/even tags to you template.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [SandraR] Alternating Row Color In reply to
In Reply To:
Andy are you saying in GT we change the link_results (where)?

sub {
my $vals = shift;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC');
my $sth = $link_db->select;
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}

Kinda :)

My suggestion, would be to do;

Code:
sub {
my $vals = shift;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC');
my $sth = $link_db->select;
my $output = '';
my $cnt = 0;
while (my $link = $sth->fetchrow_hashref) {
if ($cnt / 2) {
$link->{even} = 1;
} else {
$link->{odd} = 1;
}

$output .= Links::SiteHTML::display('link', $link);
$cnt++;
}
return $output;
}


..and then in link.html, you can use;

<%if odd%> odd color <%else%> even color <%endif%>




If using the links_loop tag, you could try something like;

Code:
<%if links_loop%>
<%loop links_loop%>
<div color="<%if odd%>red<%else%>green<%endif%>">
<include link.html%>
</div>
<%endloop%>
<%endif%>

Hope that helps :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [SandraR] Alternating Row Color In reply to
Quote:
after reading those doc - 100 different ways and eyes getting crossed - hitting the forum is the next step - not always the first step
I feel, that I gave exact directions about, where and how to find the needed code.
I did not paste the exact code, but I pointed, where you can find it.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Alternating Row Color In reply to
Not everyone is a programmer though ;) Reading documentation is one thing ... but understanding it is another <G>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [fuzzy logic] Alternating Row Color In reply to
Thanks for the tips everyone but I think I'm still missing the point. I looked at the doc's and they reference pens but show hair color in the example but logic is logic right?? With the right color pens I could draw hair back on my head Wink..

I think my problem is in placement.. I have tried to place the odd even in my link.html template but that doesn't recognize odd/even.

Then I tried to place it in my category.html template where it calls the <%links%> . Hopefully I didn't include too much code but I don't want to miss anything..

<%--
File : category.html
Description : This file displays a single category page.
Tags : On this page, you have all the properties of the category
you are viewing, plus:
links => A list of all links in this category.
links_loop => A loop of all the links in this category.
--%>
<%if links%>
<%header_row%>
<td width=200> <%header_font%>
LINKS:
<%/header_font%></td>
<td bgcolor="white">&nbsp;</td>
</tr> <%if next_span%>
<!-- Next/Previous links if spanning pages. -->
<tr>
<td align="right" colspan=2><%body_font%>
&nbsp; <small>Pages:
<%next_span%>
</small></td>
</tr>
<%endif%>
<tr>
<td colspan=2> <%body_font%>
<!-- Header for the link table. -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100"><div align="center">
<%body_font%>
Start</div></td>
<td width="100"><div align="center">
<%body_font%>
End</div></td>
<td width="150"><div align="center">
<%body_font%>
Event Name</div></td>
<td width="125"><div align="center">
<%body_font%>
City</div></td>
<td width="25"><div align="center">
<%body_font%>
State</div></td>
</tr>
<tr>
<td colspan="5"><hr></td>
</tr>
</table>
<!-- End Header for the event table. -->
<%links%>
</td>
</tr>
Example from Doc's
<%loop results%>
<tr><td bgcolor="<%if even%>white<%else%>silver<%endif%>">..</td></tr>
<%endloop%>


I even tried replacing the <%links%> section with the code below
<%loop links_loop%>
<div color="<%if odd%>white<%else%>silver<%endif%>">
<include link.html%></div>
<%endloop%>


I hunted around the GT directory to find the sub you show modifying but couldn't determine which one to make changes in..

Andy, thanks for the understanding that we aren't all programmers.. I definately fall under the category of "Just enough to be dangerous"..
Quote Reply
Re: [Andy] Alternating Row Color In reply to
I thought, template editing does not need programming knowledge Angelic

I thought, finding and pasting the following code should be not a problem:
Code:
<%loop results%>
<tr><td bgcolor="<%if even%>white<%else%>silver<%endif%>">..</td></tr>
<%endloop%>

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
Quote:
I hunted around the GT directory to find the sub you show modifying but couldn't determine which one to make changes in..
category.html is the file, where you should do that change.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
Tony,

I prefer using the Global methods. Go to Build>Template Globals>

change the option:
link_results

from :
sub {
my $vals = shift;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC');
my $sth = $link_db->select;
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}



to what andy suggested:
sub {
my $vals = shift;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC');
my $sth = $link_db->select;
my $output = '';
my $cnt = 0;
while (my $link = $sth->fetchrow_hashref) {
if ($cnt / 2) {
$link->{even} = 1;
} else {
$link->{odd} = 1;
}

$output .= Links::SiteHTML::display('link', $link);
$cnt++;
}
return $output;
}



Then open link.html and add the
<%if odd%> odd color <%else%> even color <%endif%>



TRY THAT



Sandra Roussel
Chonsa Group Design - Fresh Start Housing

Last edited by:

SandraR: Mar 16, 2005, 10:35 AM
Quote Reply
Re: [SandraR] Alternating Row Color In reply to
Note, your global solution means a duplicate, unneeded database query.

While the template based links_loop has already done the database query once, and the database query was more effective, as it was likely using the LIMIT option.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Post deleted by SandraR In reply to
Quote Reply
Re: [webmaster33] Alternating Row Color In reply to
Well, I tried adding the GT and code like Sandra suggested but couldn't get it to work. I even went back and tried to simply paste the code below in my category.html and got negative results.. It still seems to just take the <%else%> color and apply it to the rows..
Code:

<%loop results%>
<tr><td bgcolor="<%if even%>white<%else%>silver<%endif%>">..</td></tr>
<%endloop%>


I must be missing something very obvious or my reading comprehension is seriously lacking..
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
Oh, I should have mention, that the "results" should be replaced to "links_loop". Sorry.

<%loop links_loop%>
<tr><td bgcolor="<%if even%>white<%else%>silver<%endif%>">..</td></tr>
<%endloop%>

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Mar 17, 2005, 7:59 AM
Quote Reply
Re: [webmaster33] Alternating Row Color In reply to
Nothing to be sorry for WM.. I had seen that in one of the doc's and tried it.. The problem when I tried that is that I get the alternating colors with only the " .. " in each row.

Quote:

Code:
<%loop links_loop%>
<tr><td bgcolor="<%if even%>white<%else%>silver<%endif%>">..</td></tr>
<%endloop%>


It's as if when I do this it's not calling my link.html template. I tried replacing the " .. " with <%links%> and it placed/repeated all the links in the odd cells..
> >