Bob's Good Stuff Lists

Powered by Gossamer Threads

Using Multiple Category Templates With Links v2.0
Copyright © 2000 Connors
All Rights Reserved

*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*

This mod may be used for personal use by users of the Gossamer Threads, Inc's Links v2.0 script. All other rights to the code and documentation for this mod are reserved, under copyright, by the author. Redistribution or republication of this mod and its instructions, without permission, is prohibited.

Purpose:

Many people want to customize the Links v2.0 setup to use different templates for different purposes. For example, a particular category page may need a different layout than what is used on other category pages. To see specifically what I mean, compare the following four pages on my web site:

The instructions contained here will provide you a way of accomplishing the same type of setup for your category pages. It should be noted that this technique can also be used for other templates but $category_name cannot be used outside the Category templates. Instead, you must determine what variable should be used to load the appropriate template. Here are the instructions for using multiple templates for the Category Pages:

In site_html_templates pl, sub site_html_category:

  1. After the following line:
       # This rountine will build a page based for the current category.
    Add the following (in blue):
       my $template;
    
       # Set the appropriate template file to load
       if ($category_name =~ /^Category1/) {
         $template = "cat1.html"; }
       elsif ($category_name =~ /^Category2/) {
         $template = "cat2.html"; }
       elsif ($category_name =~ /^Category3/) {
         $template = "cat3.html"; }
       else { $template = "category.html"; }
    where "Category1", "Category2", and "Category3" are the names of the categories you have special templates for, and "cat1.html", " cat2.html", and "cat3.html" are the template files to load for those categories. See the Notes below.

  2. Change this line:
       return &load_template ( 'category.html', {
    to read:
       return &load_template ( $template, {
Notes:
  1. This multiple template mod will work for all categories and their subcategories. That is, if you change Category1 to read Software and you have a Software/Utilities category, cat1.html will be loaded for both the Software and Software/Utilities categories. If this is not what you want, then you should change the code to read:
       # Set the appropriate template file to load
       if ($category_name =~ /^Software\/Utilities/) {
         $template = "category.html"; }
       elsif ($category_name =~ /^Software/) {
         $template = "cat1.html"; }
       else { $template = "category.html"; }
  2. The above code always searches for a pattern starting at the beginning of the category name field. If you are trying to load a special template for just a sub-category, you will need to modify the code similar to that in Note 1 but specify a different template as shown below:
       # Set the appropriate template file to load
       if ($category_name =~ /^Software\/Utilities/) {
         $template = "cat1.html"; }
       else { $template = "category.html"; }
    The above code will load the cat1.html template only when the category name is Software/Utilities and will load category.html for all other category names, including Software.

You are now ready to use multiple templates on your Category pages with Links v2.0. If you have any problems, you may request assistance by posting in the Gossamer Threads' Links 2.0 Customization Forum or by sending email to Bob Connors.

*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*

This Site Hosted By
Orphanage Services
Powered By Apache