Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

bicolor links

Quote Reply
bicolor links
Hi,
I posted a message at the links 2.0 Modification Forum about how to create bicolor links with something like:
my $bgcolor ;
unless ($bi==1) {
$bgcolor="#F6F6F6";
$bi=1;
} else {
$bgcolor="#FFFFFF";
$bi++;
}

widgetz published another way and now I wanted to use either of them for links sql but somehow it does not work. Isnīt it possiple to include this perl code in the .pm files? Any help is appreciated.

Ciao

Niko

http://www.master-productions.com
Quote Reply
Re: bicolor links In reply to
You'd want to set this in the HTML_Tempates.pm file, at the top, either above the globals, then pass 'bgcolor'=>$bgcolor into the %GLOBALS hash.

I've used the idea from the 'templates.cfg' file for Links 2.0 in my re-design of the Links.pm and mostly the HTML_Templates.pm file. Those defaults were included at the top of the ffile (all defined with 'my') then were added to the %GLOBALS hash.

My hash has about 60 items in it, but that's not much, actually.

I can set all my template colors, backgrounds, logos, advertisers, etc from that one file. The only time I edit my templates is for bug fixes, or to tweak them more. Everthing else is in the HTML_Templates.pm file or in a set of [location].inc files -- for all my headers, advertisers, etc. It probably adds 30% to the build time, but it makes site management a breeze! (yeah.... after 100+ hours re-designing all the templates <G>)



Quote Reply
Re: bicolor links In reply to
O.K. I think I have understood so far. I guess my problem is that I do not understand the strict thing. Seems like I have to define everything with my or it does not work. The problem is that if I have the code like that:

my $bgcolor;
my $bi;
unless ($bi==1) {
$bgcolor="#F6F6F6";
$bi=1;
} else {
$bgcolor="#FFFFFF";
$bi++;
}
%GLOBALS = (
date => \&Links::DBSQL::get_date,
time => \&Links::DBSQL::get_time,
db_cgi_url => $LINKS{db_cgi_url},
build_root_url => $LINKS{build_root_url},
site_title => $LINKS{build_site_title},
css => $LINKS{build_css_url},
bgcolor => $bgcolor,
banner => ''
);

It does not get me anywhere because the color does not change and if I do it without my it does not work. Sorry but I donīt know how to do that

Ciao

Niko

http://www.master-productions.com
Quote Reply
Re: bicolor links In reply to
Still did not solve the problem so I still would appreciate any help.

Ciao

Niko

http://www.master-productions.com
Quote Reply
Re: bicolor links In reply to
I think it's working, but I think you are setting the background color in the wrong place.

I think we were out of sync on what you were trying to do. Here's a bit of a rethink of the process.

What you'd want to do is put the routine to set the link color IN EACH of the routines that goes to build the link. Because every time you build a link, you want to switch the colors.

The easiest way to do it is probably to set two colors in the %GLOBALS area, $Link_LIght and $Link_Dark (or as I do later $link_even_color and $link_odd_color).

Then, in each routine where you go to build the link, you need to count where you are, and set the $rec->{BG_Color} (or similar) to either the $Link_Light or $Link_Dark color.

The _best_ way to do it, so you make all odd links light, and all even links dark (or vice versa) AND so that you can set the colors in the "templates" areas and not the body code, is to use a line like: (where $link_count is your counter variable)

Code:
if ($link_count/2 == int ($link_count/2) ) { ## even # link
$rec->{BG_color}="Even";
} else {
$rec->{BG_color}="Odd";
}
.

Then, in the link.html template, you would add:
.

Code:
<%if BG_color eq 'Even'%>
BGCOLOR = %link_even_color
<%endif%>
<%if BG_color eq 'Odd'%>
BGCOLOR = %link_odd_color
<%endif%>
.
(NOTE: I changed the $Light_Color and $Dark_Color to the Even/Odd colors for clarity).

What this does...

1) It lets you define the colors in the HTML_Templates.pm file (rather than in the Links.pm file).
2) It lets you put a "generic" Even/Odd counter before the calls to the $site_html_link calls
3) It lets you pass the "color" to the links.html template, without knowing what the colors are -- (all you are passing is an Even/Odd value, not a color).
4) It sets it up to allow you to do more complex formatting based on the even/odd than on the passed color.

Let me know if this works for you. It's early, and I may have missed something, but this is more complete for what you are trying to do.

The problem you are hitting is that the HMTL_Templates.pm is only available once you call the templates. It's initialized too early to be used the way you are doing it. You have to create the "spaces" for the colors and then assign them once you call the template. You need to re-assign the values on the fly.

Otherwise, you could define the Light/Dark or Even/Odd color in the Links.pm file, and using the odd/even test above, assign the correct color to the passed $rec->{BG_color} variable, but it's less logical that way, since it puts the formatting information in the body code, not the template.

BTW -- you need to make sure the $link_count variable is initialized properly (to 1 or 0 depending on where you increment it) and you need to remember that you've "magically" created a new parameter for the passed %rec hash of BG_color. That's not a real problem, but you'd probably want to document those changes in any production type environment.

The &site_html_link routine is called anywhere you have the links displayed -- the build_category_pages, build_new, build_cool, and any special pages you might have built in.



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/