Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Alternating Row Color

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..
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
Quote:
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..

Yes, because the example showed .. string as place holder Smile

Here's the fix again:
Code:
<table>
<%loop links_loop%>
<tr><td bgcolor="<%if even%>white<%else%>silver<%endif%>">
<include link.html%>
</td></tr>
<%endloop%>
</table>

Now I checked the whole code, and should work if everthing goes well.

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
Sometimes I think things just aren't meant to be.. Crazy
I pasted your code in place of my <%links%> code. and get nothing...

I've attached a before and after image of what I'm getting so you can see what I'm seeing..
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
Hehe, I should also read more the docs Wink
And I should not hurry so much with the answers... I'm busy now with my diploma work...

Code:
<table>
<%loop link_results_loop%>
<tr><td bgcolor="<%if even%>white<%else%>silver<%endif%>">
<include link.html%>
</td></tr>
<%endloop%>
</table>

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
Hi,

Shoot over LinksSQL access, and I'll take a quick look for you. Probably something simple, like a mis-positioned tag or such :)

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: [tondelo] Alternating Row Color In reply to
Note, you can anytime, use the
<%GT::Template::dump%>
tag, to display available tags in LSQL v2.2.x and below. LSQL 2.99 changed the syntax.

But WARNING, this should not be used on production site, so you should use on only on your offline site, or a test installation, only! You can limit the display to your registered username, so this can be made safe. I can dig the code for you if you need 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
Quote:
I can dig the code for you if you need it.

Code:
<%if Username eq "Username"%>
<%GT::Template::dump%>
<%endif%>

Smile

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: [tondelo] Alternating Row Color In reply to
I went to the resources to find you something useful,
and came up with this fine example:
Displaying Links In Two Columns

It's a good example how looping works in the template.

Unfortunately there is no Template Tutorial in Links 2.2.x, but there will be in Links v3.x.

P.S.: Thanks, Andy Cool

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, 10:07 AM
Quote Reply
Re: [Andy] Alternating Row Color In reply to
In Reply To:
Hi,

Shoot over LinksSQL access, and I'll take a quick look for you. Probably something simple, like a mis-positioned tag or such :)

Cheers

Hi Andy,

I shot it over to the addr you have in your sig..

Let me know if you have any question.
Quote Reply
Re: [tondelo] Alternating Row Color In reply to
All done :)

For future reference, this was the final code;

Code:
<table width="100%">
<%loop links_loop%>
<tr>
<td bgcolor="<%if even%>white<%else%>silver<%endif%>">
<%include link.html%>
</td>
</tr>
<%endloop%>
</table>

Enjoy =)

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: [Andy] Alternating Row Color In reply to
Hmmm... This is the same code I suggested in my Post #26:
http://www.gossamer-threads.com/...i?post=278709#278709

Is it possible, that tondelo did not try that code?

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
Within Links SQL Help/Templates/Template Syntax page, the documentation explains the template "loop" feature, showing the "link_results_loop" usage in the example:
Quote:
Loops:
If you are feeling a bit overwhelmed, then you can skip this part. Loops are an advanced feature that provide complete control over the layout of the directory. Perhaps you don't like the fact that the same link.html template is used when displaying a list of search results and for displaying the links in the category page. Well, by default Links SQL only provides you with a <%link_results%> tag, so there is not much you can do, right? Wrong! For all of the major tags, you can use loops instead. Let's look at search results. Instead of:

<p>Here are your matching links:<br><br><%link_results%></p>

You could do:

<p>Here are your matching links:<br><br>
<%loop link_results_loop%>
<a href="<%URL%>"><%Title%></a>: <%Hits%>
<%endloop%>

So inside the <%loop%> and <%endloop%> tag you have a series of links, and you can use any link attribute you like. However, don't forget you can also use includes, so you could do:

<p>Here are your matching links:<br><br>
<%loop link_results_loop%>
<tr><td><%include link.html%></td></tr>
<%endloop%>

Now link.html will be loaded and parsed!


Now something is strange, as Andy says links_loop is working, and link_results_loop doesn't in category.html.

Finally I went into the templates and checked what is the truth about the loop variables.

The result of the loop investigation is the following:
  • On home.html following loops are available: category_loop
  • On category.html following loops are available: links_loop, category_loop, related_loop
  • On new.html following loops are available: link_results_loop, title_linked_loop, (and if you don't have span pages turned on, then the loop contains a list of dates with: new_date, links)
  • On new index page following loops are available: link_results_loop
  • On new subpage following loops are available: link_results_loop
  • On cool.html following loops are available: link_results_loop
  • On rate_top.html following loops are available: top_rated_loop, top_votes_loop
  • On review_search_results.html following loops are available: Review_Loop
  • On search_results.html following loops are available: link_results_loop, category_results_loop

    These informations are usually available in the header part of these templates.


    It seems, that GT did not follow the same loop naming scheme, so for home.html, category.html, review_search_results.html uses different loop naming scheme.

    Probably would be fine if GT would unify these naming schemes (while backward compatibility should be kept for next few versions...).
    Or at least a unified documentation, like the above one should be published.

    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
    In Reply To:
    Hmmm... This is the same code I suggested in my Post #26:
    http://www.gossamer-threads.com/...i?post=278709#278709

    Is it possible, that tondelo did not try that code?

    WM, you are correct, the only difference in the two is the width being set which has absolutely no bearing on the functionality of the snippit..

    The fact that I did try everyones suggestions has me puzzled as to why I couldn't get it working back on your #26 post.. I don't know if I put it in the wrong location or the wrong template but it was obviously somthing on my end..

    Thanks to everyone for the help on this and I can't wait to see the added tutorials in Links v3.x..
    Quote Reply
    Re: [tondelo] Alternating Row Color In reply to
    You are welcome!
    I'm glad, that finally works the way you wanted.

    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...