Gossamer Forum
Home : Products : Links 2.0 : Customization :

Separate Category HTML Pages

Quote Reply
Separate Category HTML Pages
I looked in the message boards here and I couldn't find the answer to this question.

I want to have a different html for each category. how do I do this using the templates. I want Links 2.0 build feature to build category pages that I make. I want a few category pages to look different from the default ones.

Thanks
Evan
Quote Reply
Re: Separate Category HTML Pages In reply to
Create your template files for each category and save them in the templates directory. Then, go to sub site_html_category in site_html_templates.pl and do this:

Code:
my $template_name;
if ($category_name =~ "Category1") {
$template_name = "cat1.html"; }
elsif ($category_name =~ "Category2") {
$template_name = "cat2.html"; }
elsif ($category_name =~ "Category3") {
$template_name = "cat3.html"; }
else { $template_name = "category.html"; }

Where "Category1", "Category2", and "Category3" are the names of the categories you are using, and cat1/cat2/cat3.html are the corresponding template files you want to use for those categories.

Then change:

Quote:
return &load_template ( 'category.html', {

to read:

Quote:
return &load_template ( $template_name, {

I hope this helps.


[This message has been edited by Bobsie (edited March 11, 1999).]
Quote Reply
Re: Separate Category HTML Pages In reply to
This is the error message I get when I add the code

Error including libraries: syntax error at /home/compu-te/HTML/cgi/admin/site_html_templates.pl line 153, near "elsif {"
syntax error at /home/compu-te/HTML/cgi/admin/site_html_templates.pl line 155, near "else"

Make sure they exist, permissions are set properly, and paths are set correctly.

Thanks

Evan
Quote Reply
Re: Separate Category HTML Pages In reply to
Change the "{" after the last "elsif" to a "(" (that would be in line 153 of your code) ... I made a typo. I tried to edit it but the code doesn't show up in the editor.

The second syntax error in your error message at line 155 is caused by the same typo in line 153. Once corrected, both should go away.

P.S., I finally figured out a way to edit the erroneous code. It is fixed now.

[This message has been edited by Bobsie (edited March 11, 1999).]
Quote Reply
Re: Separate Category HTML Pages In reply to
Thanks Bobsie it works great
Quote Reply
Re: Separate Category HTML Pages In reply to
Suddenly I have a use for this, now I have a question Wink

What I want to do is have the "home" page be a general index, and have each main category page be a "mini" home page for that particular topic (it would only show its own subcats, no links). I want those mini homes to have unique formatting according to topic, and their subcats would carry the same general formatting, but display links as usual.

This script looks like accomplishing this would require a huge number of elsifs because each topic will have numerous subcats that I would have to code in (of course, I could be wrong). Is there any reason I can't add a field to category.db called "template_name" (or whatever), select the template I want to use for each category and subcategory from the admin, then then just have the script key off that field?
Quote Reply
Re: Separate Category HTML Pages In reply to
bobsie..

isn't

$blah =~ "blah blah"

used for pattern matching?

although it works.. i beleive you should change it to

$blah eq "blah blah"

or better yet

$blah =~ /^blah blah/

the third one will match anything in the category.. even in the subcategories.. so you can have the whole branch that style templates..
Quote Reply
Re: Separate Category HTML Pages In reply to
That's helpful, but I would still a separate template for the category and then one for all its subcats (the main cat page would have some unique info I wouldn't wan't to reproduce on every page). Maybe if once I establish the main cat I could use a second if/else to check for a / in the cat name to pick the right template?
Quote Reply
Re: Separate Category HTML Pages In reply to
Nevermind...while searching for something else I found details on adding a template category field like I first mentioned at:
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/001985.html

Should cover exactly what I wanted to do Smile
Quote Reply
Re: Separate Category HTML Pages In reply to
I am trying to reconfigure my site to use the separate category templates, and I am having problems.

I changed the code, as stated above, and created three template files (just took the category.html and added a phrase after the body tag for a test), uploaded the three test html files to my templates directory, uploaded the new site_templates_html.pl file and ran the 'build-all'. Everything went fine.....until I went to view the pages. After the home page, all I get is a blank page with some greek letters in the upper left corner? None of my pages show up, not even the ones that aren't referenced in the 'if' statement. What gives?
The following is the code I put in my site_templates_html.pl file.

Code:
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.
my $template;
# Set the appropriate template file to load
if ($category_name =~ "Antiques") {
$template = "antiques.html"; }
elsif ($category_name =~ "Antiques/Ancient_World") {
$template = "ancient_world.html"; }
elsif ($category_name =~ "Auctions") {
$template = "auctions.html"; }
else { $template = "category.html"; }

return &load_template ( $template_name, {
Quote Reply
Re: Separate Category HTML Pages In reply to
you are using:

$template_name

instead of

$template when you load the template..

this code will not work with subcategories.. as i said above.. use

Code:
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.
my $template;
# Set the appropriate template file to load
if ($category_name =~ /^Antiques/Ancient_World/") {
$template = "ancient_world.html"; }
elsif ($category_name =~ /^Antiques/) {
$template = "antiques.html"; }
elsif ($category_name =~ /^Auctions/) {
$template = "auctions.html"; }
else { $template = "category.html"; }

return &load_template ( $template, {
Quote Reply
Re: Separate Category HTML Pages In reply to
Thanks Widgets,
I didn't read your instructions well enough. Everything works great now.
Quote Reply
Re: Separate Category HTML Pages In reply to
widgetz,

Code:
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.
my $template;
# Set the appropriate template file to load
if ($category_name =~ "Antiques") {
$template = "antiques.html"; }
elsif ($category_name =~ "Antiques/Ancient_World") {
$template = "ancient_world.html"; }
elsif ($category_name =~ "Auctions") {
$template = "auctions.html"; }
else { $template = "category.html"; }

return &load_template ( $template_name, {

You need to test for Antiques/Ancient_World before testing for Antiques because Antiques will "pattern match" in both cases. Since it was being tested first (and returned TRUE), the code never saw the test for Antiques/Ancient_World. It's a moot point now though because even widgetz's code changed it around.

[This message has been edited by Bobsie (edited August 23, 1999).]
Quote Reply
Re: Separate Category HTML Pages In reply to
I recently tried the mod for Separate Category HTML pages. Here is the error message that I have received:

Error including libraries: Can't use global @_ in "my" at /export/home/ecommi/public_html/cgi-bin/links/admin/site_html_templates.pl line 45.

Make sure they exist, permissions are set properly, and paths are set correctly.



Can someone please help. Thank you.