Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically?

Quote Reply
How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically?
Hi!


Below you'll find two (I hope in this case: relevant) parts of sub "site_html_print_cat" from my SiteHTML.pm. Because I'm not a Perl-Guru like some of you are I'll need your advice for the following changes I'd like to do.

My goal is to change "build_category_columns" and set it to "X" (I'm not yet sure about the number) automatically if there's a category that contains (any number of) subcategories with 2 or less than 2 chars only (what I mean is: every subcategory has to have 2 or less than 2 chars; if there's just one with more than 2 chars there should be no changes). E.G. if there's:

SomeCategory

... with SubCategories named like:

0
a
0a
a0
00
aa

... I want X colums instead of the number of colums I defined in "Setup".

I think there's some "$columns" (or "my $columns" ?) needed to replace "$CFG->{build_category_columns})" ... but I have no idea how and where to write the "if then"-thing to get this new "$columns" that could replace $CFG->{build_category_columns})"!? :-/


sub site_html_print_cat {
# --------------------------------------------------------
# This routine prints out a list of categories.
#
my $subcat = shift;
my $parent_cat = shift @$subcat;
my $breakpoint = int (($#{$subcat}+1) / $CFG->{build_category_columns}) + ( (($#{$subcat}+1) % $CFG->{build_category_columns}) ? 1 : 0);
my $table_head = $CFG->{build_category_table} || '';
my $width = int (100 / $CFG->{build_category_columns});
my $output = '';
my $i = 0;
my $cat_db = $DB->table('Category');
my $opts = { dynamic => 0 };

...

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

if ($CFG->{build_category_columns}) {
($i > 0) and !($i % $breakpoint) and ($output .= qq| ...

Last edited by:

e: Aug 4, 2002, 3:33 AM
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
As a starting point, you may like to experiment with checking if the length of the Full_Name of the category is equal to two. You could put this as a global, and then do something like



<%if catnameislessthanorequaltotwo%>

code

<%else%>

<%endif%>

You could put this between loop_category_loop, and then use the inbuilt values for this loop such as <%iseven%> etc (look at the docs for more), to control the formatting of your display. Hacking the actual code is not the links sql way. HTH.
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
"checking if the length of the Full_Name of the category is equal to two. You could put this as a global"

How this should work is exactly what I don't understand!? Not in a global, not in SiteHTML.pm.

...

"Hacking the actual code is not the links sql way."

I'm on the way to learn the 'links sql way'. But at the moment I really need solutions ... not ways. ;-)
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
you could make a global called catnameislessthanorequaltotwo

in it, get the Full_Name of the current cat

then with it

if (length($FULL_NAME) > 2){return 0;}

else{return 1;}
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
You should find the relevant code in the globals area of the resources section to help you
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
I'm on the way to learn the 'links sql way'. But at the moment I really need solutions ... not ways. ;-)
If you can program, the best thing to do is to download a few plugins and globals and see how they work before you do any work on Link SQL whatsoever. It will save you much time and help you achieve better results in the long run.
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
"in it, get the Full_Name of the current cat"

Will I not need the Full_Names of all subcats?
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
"If you can program..."

I can't.

Still I fixed all problems I've had. The "breakpoint"-thing is the last to find a solution for.
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
"in it, get the Full_Name of the current cat"

Will I not need the Full_Names of all subcats?
It would help me to help you if you can tell me what you're trying to achieve, as I don't totally understand why you would need all of the subcats. Can you give me a description of why you want 2 letter cats etc..

Last edited by:

giovanni: Aug 8, 2002, 6:08 AM
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
"If you can program..."

I can't.

Still I fixed all problems I've had. The "breakpoint"-thing is the last to find a solution for.
You're probably going to find this quite hard then :(
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
In Reply To:
"in it, get the Full_Name of the current cat"

Will I not need the Full_Names of all subcats?
It would help me to help you if you can tell me what you're trying to achieve, as I don't totally understand why you would need all of the subcats. Can you give me a description of why you want 2 letter cats etc..

I'll have categories with A B C ... to Z subcategories and categroies with subcategories from 0 to 9 and 00 to 99 etc.

What I don't want are long lists in 2 columns but in 7 then. That's it.
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
Maybe it might be easier to use Pugdog's Alphabar Plugin?
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
You're probably going to find this quite hard then :(

That's why I like Links SQL basically. But there's this column-problem that can't be fixed via templates obviously.
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
Maybe it might be easier to use Pugdog's Alphabar Plugin?

But I'll need the 0-9 and 00-99 thing as well. That's why I want to ask IF there are subcategories with 2 or less than 2 chars and split them to 7 columns then.
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
Yep, I see where you're coming from. If I were you, I'd use the Alphabar plugin, otherwise it'll be quite complex.
Quote Reply
Re: [e] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
It shouldn't take too much modification to add this into the plugin.
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
It shouldn't take too much modification to add this into the plugin.

I'm not sure how the Alphabar plugin should help: "SHAREWARE: Allows full alphabetic searching of the database on the input field. It's a replacement in a way, for search.cgi."?
Quote Reply
Re: [giovanni] How to change "$CFG->{build_category_columns})" in sub site_html_print_cat automatically? In reply to
In Reply To:
Yep, I see where you're coming from. If I were you, I'd use the Alphabar plugin, otherwise it'll be quite complex.


1. Question

If I'd have a working "$columns_number" like explained at the "my $columns number = ..."-line and the following replacements of "$CFG->{build_category_columns}" would the whole sub work like explained above (for the A-Z, AA-ZZ, 0-9 and 00-99 subcategories with 7 instead of the predefined cat-columns)?

sub site_html_print_cat {
# --------------------------------------------------------
# This routine prints out a list of categories.
#
my $subcat = shift;
my $parent_cat = shift @$subcat;

my $columns_number = if each subcat_name_length < 3 = 7 else $CFG->{build_category_columns};

my $breakpoint = int (($#{$subcat}+1) / $columns_number) + ( (($#{$subcat}+1) % $columns_number) ? 1 : 0); # $columns_number replaces $CFG->{build_category_columns}
my $table_head = $CFG->{build_category_table} || '';
my $width = int (100 / $columns_number); # $columns_number replaces $CFG->{build_category_columns}
my $output = '';
my $i = 0;
my $cat_db = $DB->table('Category');
my $opts = { dynamic => 0 };

# Print Header.
if ($columns_number) { # $columns_number replaces $CFG->{build_category_columns}
...

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

if ($columns_number) { # $columns_number replaces $CFG->{build_category_columns}
($i > 0) and !($i % $breakpoint) and ($output .= qq| ...

# Don't forget to end the table properly ..
if ($columns_number) { # $columns_number replaces $CFG->{build_category_columns}
...


2. Question

Would the "my $columns number = ..."-line be the right place to get this IF-ELSE-thing done? If not: Where and how would this "line" have to be placed? Is there another sub needed to get it done?


3. Question

What does "$subcat" contain exactly?

Last edited by:

e: Aug 8, 2002, 7:43 AM