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

Clean Category Name?

Quote Reply
Clean Category Name?
Hi,

This must have been answered before but I cant find it anywhere. What I'd like to do is display the name of the category that the user is currently in (not the full path to the category as well).

For example, if the user had followed this path:

--> Actors & Entertainers/Entertainers/Entertainers F-J

I'd like to display the category name:

--> Entertainers F-J

on that page. Can anyone suggest how?

Thanks!

Regan.

Quote Reply
Re: Clean Category Name? In reply to
I believe if you use the &get_category_name with the &build_clean subs in the DB_Utils.pm module, you can "cleanly" print the category name in almost any template file.

I have this working in a few sections of my LINKS SQL v.1.13 site...I would post the codes for you, but I am not at my home computer...on route from a short vacation. I will try to come back later today or some time this week and post the codes for you.

Bye....

Regards,

Eliot Lee
Quote Reply
Re: Clean Category Name? In reply to
 
Thanks Eliot!

Regan.

Quote Reply
Re: Clean Category Name? In reply to
Okay...what you need to do is the following:

1) Add the following sub in the DB_Utils.pm module (don't forget to reference &build_category_clean_name at the top of the file)....

Code:

sub build_category_clean_name {
# --------------------------------------------------------
# Converts a category name into something usable by a directory/URL.
#
my $name = shift;
if ($LINKS{foreign_char}) {
my @cat = split /\//, $name;
my ($output, $id, $tmp, $level);
$level = $#cat;
for (0 .. $level) {
$tmp = join "/", @cat;
$id = &get_category_id ($tmp);
if (!$id) { $tmp =~ s/[^\w\d\_\-\/]/_/g; $id = $tmp; }
$output = "$id/$output";
pop @cat;
}
$output =~ s,/$,,;
return $output;
}
elsif ($LINKS{build_directory_field}) {
my $id = &get_category_id ($name);
if (! $CATDB) {
$CATDB = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Category.def";
}
my $rec = $CATDB->get_record ($id, 'HASH');
if ($rec->{$LINKS{build_directory_field}}) { return $rec->{$LINKS{build_directory_field}}; }
else { $name =~ s/\s/_/g; $name =~ s/[^\w\d\_\-\/]/_/g; return $name; }
}
else {
return $name;
}
}


2) Then add the following codes in your sub site_html_link routine in the HTML_Templates.pm module file:

Code:

my $catname = &Links::DB_Utils::get_category_name($tags->{CategoryID});
my $category = &Links::DB_Utils::build_category_clean_name($catname);


3) Then define the following "tags" in the same sub:

Code:

catname => $catname,
category => $category


4) Then in the link.html file, add the following codes:

Code:

<a href="<%category%>"><%catname%></a>


You may have to hack the first set of codes a bit more to remove the / character from other places like the drop-down select menus.

Regards,

Eliot Lee
Quote Reply
Re: Clean Category Name? In reply to
Thanks Eliot! I'll give that a go.

Quick reply - I thought you were meant to be on holiday!!! :)

regan.

Quote Reply
Re: Clean Category Name? In reply to
You're welcome...

I was on route home today...I got home this afternoon and after clearing out 500 email messages and addressing some technical issues with my clients, I had a few minutes to collect the codes that should help you.

Good luck!

Regards,

Eliot Lee