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

Displaying graphics in subcategory.html?

Quote Reply
Displaying graphics in subcategory.html?
Hi,

in subcategory.html is the following term used:

<%if Has_New_Links eq 'Yes'%>bla bla bla<%endif%>
<%if Has_Changed_Links eq 'Yes'%>bla bla<%endif%>

I thought about displaying individual graphics for this ... but if i've a category what has new and changed links inside i'll get both graphics displayed - how could i display a special graphic for categories with new and changed entries instead of displaying two graphics?

Thanks for hints.

Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
One thing that you could do is add the following codes in the sub site_html_print_cat routine in the HTML_Templates.pm file:

Code:

if (($rec->{Has_New_Links} eq 'Yes') and ($rec->{Has_Changed_Links} eq 'Yes')) {
$mod_image = qq|<img src="/path/image.gif" width="" height="" alt="" border="">|;
}
if ($rec->{Has_New_Links} eq 'Yes') {
$mod_image = qq|<img src="/path/diff.gif" width="" height="" alt="" border="">|;
}
if ($rec->{Has_Changed_Links} eq 'Yes') {
$mod_image = qq|<img src="/path/diff2.gif" width="" height="" alt="" border="">|;
}


Then define the following tag in the same subroutine:

Code:

mod_image => $mod_image


Remeber that you have to have a comma at the end of the field/hash value before this tag definition if it is the last tag you define....

Then in your subcategory.html file, add the following tag:

Code:

<%mod_image%>


BTW: Confirmation of suggestions provided to you in the forums would be appreciated...Wink

Regards,

Eliot Lee

Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Eliot,

In Reply To:
BTW: Confirmation of suggestions provided to you in the forums would be appreciated...

you're too fast for me ... thank you for your great assistance.

I'm just editing as you described before - maybe you could give me a shorthand where i've to insert the

mod_image => $mod_image

exactly?

Thanks again!


Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
See the following codes:

Code:

$output .= &load_pages_template ('subcategory.html', { %$cat_r, %GLOBALS }, undef, $template);


You simply add , mod_image => $mod_image AFTER %GLOBALS...

Like the following:

Code:

$output .= &load_pages_template ('subcategory.html', { %$cat_r, %GLOBALS, mod_image => $mod_image }, undef, $template);


Also...you will need to replace $rec-> with $cat_r-> in the codes I provided before...sorry about that.

Regards,

Eliot Lee

Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Hi Eliot,

sorry to bother you ... seems that this will not work ... could you take a look?

-snip-


sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#
my ($subcat, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
my @names = keys %{$subcat};

my ($output, $category_name, $category_url, $i, $cat, $cat_r, @subnames);
my $breakpoint = int (($#names+1) / $LINKS{build_category_columns}) + ( (($#names+1) % $LINKS{build_category_columns}) ? 1 : 0);

# Print Header.
$output = qq|<div class="margin"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;
$i = 0;
foreach $cat (sort @names) {
$cat_r = $subcat->{$cat};

# Get the URL and the Category name.
$category_url = $LINKS{build_root_url} . "/" . &build_clean_name ($cat_r->{Name}) . "/";
($cat_r->{Name} =~ m,.*/([^/]+)$,) ? ($category_name = $1) : ($category_name = $cat_r->{Name});
$cat_r->{Short_Name} = $category_name;
$cat_r->{URL} = $category_url;

if (($cat_r->{Has_New_Links} eq 'Yes') and ($cat_r->{Has_Changed_Links} eq 'Yes')) {
$mod_image = qq|<img src="images/redgreenfolder.gif" width="16" height="16" alt="New & Update" border="0">|;
}
if ($cat_r->{Has_New_Links} eq 'Yes') {
$mod_image = qq|<img src="images/redfolder.gif" width="13" height="16" alt="New!" border="0">|;
}
if ($cat_r->{Has_Changed_Links} eq 'Yes') {
$mod_image = qq|<img src="images/greenfolder.gif" width="13" height="16" alt="Update!" border="0">|;
}

# If you are using the three level new, calculate the number of days old.
if ($LINKS{build_days_old}) {
if ($cat_r->{'Has_New_Links'}) {
$cat_r->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $cat_r->{'Newest_Link'});
}
else { $cat_r->{'Days_Old'} = ''; }
}

# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
($i and ($i % $breakpoint)) or ($output .= qq|</td><td class="catlist" valign="top">\n|);
$i++;
defined $dynamic and &load_user ($dynamic, $cat_r);
$output .= &load_pages_template ('subcategory.html', { %$cat_r, %GLOBALS, mod_image => $mod_image }, undef, $template);
}
# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

-snip-

I've got a "compilation error" on executing nph-build.cgi ...

Thanks again!



Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
In Reply To:
I've got a "compilation error" on executing nph-build.cgi ...
That doesn't help me much...

But I did notice that I neglected to include the single quotes in the record hash values....

Use the following codes instead:

Code:

if (($cat_r->{'Has_New_Links'} eq 'Yes') and ($cat_r->{'Has_Changed_Links'} eq 'Yes')) {
$mod_image = qq|<img src="images/redgreenfolder.gif" width="16" height="16" alt="New & Update" border="0">|;
}
if ($cat_r->{'Has_New_Links'} eq 'Yes') {
$mod_image = qq|<img src="images/redfolder.gif" width="13" height="16" alt="New!" border="0">|;
}
if ($cat_r->{'Has_Changed_Links'} eq 'Yes') {
$mod_image = qq|<img src="images/greenfolder.gif" width="13" height="16" alt="Update!" border="0">|;
}


Also, there might be conflicts with the following codes in the subroutine:

Code:

# If you are using the three level new, calculate the number of days old.
if ($LINKS{build_days_old}) {
if ($cat_r->{'Has_New_Links'}) {
$cat_r->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $cat_r->{'Newest_Link'});
}
else { $cat_r->{'Days_Old'} = ''; }
}


You may have to rem out these codes (#) or delete them in order for the codes I provided you to work.

Also...helpful piece of advice...to check the syntax of your files, you should use telnet and the following commands:

Code:

perl -c HTML_Templates.pm


OR

Code:

perl -w HTML_Templates.pm


The former will give you more details about compilation errors usually caused by syntax errors in your files. The latter will check functions, variables, etc. to see if you have configured the script/file correctly.

Regards,

Eliot Lee


Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Hi Eliot,

Telnet/Perl -c says:

"Global symbol "$mod_image" requires explicit package name at HTML_Templates2.pm
line 635."

Hmm?

Regards,
Chef


Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Eliot,

i've just found the error:

you've to change additionally the line:

my ($output, $category_name, $category_url, $i, $cat, $cat_r, @subnames);

to:

my ($output, $category_name, $category_url, $i, $cat, $cat_r, $mod_image, @subnames);

After this i've got the next error:

Undefined subroutine &Links::HTML_Templates::load_pages_template called at Links/HTML_Templates.pm line 657

Seems that this nifty idea starts to be a never ending story ;)


Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Gotcha:

Change the line:

$output .= &load_pages_template ('subcategory.html', { %$cat_r, %GLOBALS, mod_image => $mod_image }, undef, $template);

to:

$output .= &load_template ('subcategory.html', { %$cat_r, %GLOBALS, mod_image => $mod_image }, undef, $template);

And it works!



Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Eliot,

thanks for your hints - now i want to add the same function to link.html - would be cool if you could take a look at this:

-snip-
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like. Due to overhead, you can't use user variables here, only
# on main pages.
#
my ($rec, $dynamic) = @_;
my ($mod_image_link);
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $rec eq 'HASH') or croak "HTML_TEMPLATES: Argument '$rec' must be hash reference";

# Set new and pop to either 1 or undef for templates.
($rec->{'isNew'} eq 'Yes') ? ($rec->{'isNew'} = 1) : (delete $rec->{'isNew'});
($rec->{'isChanged'} eq 'Yes') ? ($rec->{'isChanged'} = 1) : (delete $rec->{'isChanged'});
($rec->{'isPopular'} eq 'Yes') ? ($rec->{'isPopular'} = 1) : (delete $rec->{'isPopular'});

if ($rec->{isNew} eq 'No') {
$mod_image_link = qq|Nein<img src="images/yellowfolder.gif" width="13" height="16" alt="" border="0">|;
}
if ($rec->{isNew} eq 'Yes') {
$mod_image_link = qq|Neu<img src="images/redfolder.gif" width="13" height="16" alt="New!" border="0">|;
}
if (($rec->{isNew} eq 'Yes') and ($rec->{IsChanged} eq 'Yes')) {
$mod_image_link = qq|NeuChanged<img src="images/redgreenfolder.gif" width="13" height="16" alt="Update!" border="0">|;
}
if ($rec->{isChanged} eq 'Yes') {
$mod_image_link = qq|Changed<img src="images/greenfolder.gif" width="13" height="16" alt="Update!" border="0">|;
}
if ($rec->{isPopular} eq 'Yes') {
$mod_image_link = qq|pop<img src="images/hotredfolder.gif" width="13" height="16" alt="Popular!" border="0">|;
}

# Figure out how many days old it is if it's a new link.
if ($LINKS{build_days_old}) {
if ($rec->{'isNew'}) {
$rec->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $rec->{'Add_Date'});
$rec->{Mod_Add_Date} = &convert_date ($rec->{Add_Date});
}
else { $rec->{'Days_Old'} = ''; }
}
my $user = {};
defined $dynamic and &load_user ($dynamic, $user, $rec->{CategoryID});
my $output = &load_template ('link.html', {
detailed_url => "$LINKS{build_detail_url}/$rec->{'ID'}$LINKS{build_extension}",
%$rec,
%$user,
%GLOBALS,
mod_image_link => $mod_image_link
}, undef, $template);
# Don't clean output on a single link.
return $output;
}
-snip-

I do not get any error message on this but it seems that the new variable <%mod_image_link%> is blank ... what am i doing wrong?



Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
What about keeping it all in the templates, to avoid major code changes:

Code:
<%if Has_New_Links eq 'Yes'%>
<%if Has_Changed_Links eq 'Yes'%>
print has_new_has_changed graphic
<%endif%>
<%if Has_Changed_Links eq 'No'%>
print has_new graphic
<%endif%>
<%endif%>
<%if Has_New_Links eq 'No'%>
<%if Has_Changed_Links eq 'Yes'%>
print has_changed graphic
<%endif%>
<%endif%>
It's a little strange, but it keeps all the processing in the TEMPLATE, rather than in non-portable code modifications.




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

Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Puhdog,

that's what i needed Shocked !

I'm struggling for hours about this stuff ... add this immediatly to your FAQs!

Btw .. same thing for link.html?

Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Eliot,

would be great if you could take a look at my try to do the same thing on link.html as listed here ... thanks a lot!


Quote Reply
Re: Displaying graphics in subcategory.html? In reply to
Hi!

Just change the 'HasNewLinks' to 'isNew', and 'HasChangedLinks' to 'isCool' in pugdog's example.

Cheers,

Alex

--
Gossamer Threads Inc.