Gossamer Forum
Home : Products : Links 2.0 : Customization :

different templates for different categories?

Quote Reply
different templates for different categories?
I'm currently using the following code in site_html_templates.pl to load a different template for a few special top level categories:
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 =~ "Category_1_Name") {
$template = "cat1.html"; }
elsif ($category_name =~ "Category_2_Name") {
$template = "cat2.html"; }
else { $template = "category.html"; }
However, I now need to use a different template for a sub category of special category 1 above, and I cannot figure out how to do this.

I need Category_1_Name to use cat1.html as a template,
Category_1_Name/Subcategories to use cat1sub.html as a template,
and the rest of the categories to use the standard category.html template.

Any pointers? I don't know how to distinguish the category's subcategories from the category itself using the above code since they also match the check.

Thanks very much.

P.S. The original mod above was also from these forums.

Quote Reply
Re: different templates for different categories? In reply to
Why couldn't you use this.......?


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 =~ "Category_1_Name")
{$template = "cat1.html"; }
if ($category_name =~ "Category_1_Name_subname")
{$template = "cat1_subname.html"; }
elsif ($category_name =~ "Category_2_Name")
{$template = "cat2.html"; }
else { $template = "category.html"; }

Here's one of the lines from my file.....

if ($category_name =~ "Collectibles/Advertising") {
$template = "advertising.html"; }

You could just give your main category templates a base name (ie...Category1.html) and assign a sub-name to the child category templates (ie...Category1a.html, Category1b.html, etc.),,, or Autos.html (main) and Autos-chevy.html (child).



Quote Reply
Re: different templates for different categories? In reply to
Thanks very much!

It seems that I have to do it in the order

if cat1/subcat1 -> cat1sub1.html
elsif cat1/subcat2 -> cat1sub.html
elsif cat1 -> cat1.html
elsif cat2 -> cat2.html
else general cat -> cat.html

I first was trying with the if cat1 before the if cat1/subcat1 and that didn't work (the subcats got the parent cat template.) Then I tried what you suggessted, using all if statements for cat1, cat1/subcat1 and cat1/subcat2, and this resulted in cat1 reverting to the standard cat.html (the same as the last else statement.)

It would seem that I can only use one if statement followed by elsif statements.

I finally got it working though in the order above.

I had given up until your reply, so thanks for getting me on the right track.

P.S. To make matters worse I'm behind a terrible caching proxy so even hitting shift+reload several times I was still seeing my previous changes to confuse the matter. So I apprecaite you getting me going again and now all is working well.

Quote Reply
Re: [marinedesign] different templates for different categories? In reply to
Hi,
I have used this bit of code, it works well, but I wish to use this code in a catagory with say template1 with lots of subcatagories, that would all use the same template2, it would take a lot of: else, if statements, for each subcatagory when Im using the same one for each...
Code:
($category_name =~ "Category_1_Name")
{$template = "template1.html"; }
elsif ($category_name =~ "Category_1/all
subcatagories") {$template = "template2.html"; }
else { $template = "category.html"; }
Is there any bit of code or wildcard to put after the Catagory1/? that would tell it to use a certain template for the rest of the subcatagories in the catagory?

Any Ideas? I'd really appreciate it....
Quote Reply
Re: [marinedesign] different templates for different categories? In reply to
Hi,
I have used this bit of code, it works well, but I wish to use this code in a catagory with say template1 with lots of subcatagories, that would all use the same template2, it would take a lot of: else, if statements, for each subcatagory when Im using the same one for each...
Code:
($category_name =~ "Category_1_Name")
{$template = "template1.html"; }
elsif ($category_name =~ "Category_1/all
subcatagories") {$template = "template2.html"; }
else { $template = "category.html"; }
Is there any bit of code or wildcard to put after the Catagory1/? that would tell it to use a certain template for the rest of the subcatagories in the catagory?

Any Ideas? I'd really appreciate it....
Quote Reply
Re: [marinedesign] different templates for different categories? In reply to
Hi,
I have used this bit of code, it works well, but I wish to use this code in a catagory with say template1 with lots of subcatagories, that would all use the same template2, it would take a lot of: else, if statements, for each subcatagory when Im using the same one for each...
Code:
($category_name =~ "Category_1_Name")
{$template = "template1.html"; }
elsif ($category_name =~ "Category_1/all
subcatagories") {$template = "template2.html"; }
else { $template = "category.html"; }
Is there any bit of code or wildcard to put after the Catagory1/? that would tell it to use a certain template for the rest of the subcatagories in the catagory?

Any Ideas? I'd really appreciate it....
Quote Reply
Re: [$loth] different templates for different categories? In reply to
Hi, why don't you just use Glennu's Mod which allows you to use a different template for each category and or link, through the admin.

Hope this helps Tongue
Quote Reply
Re: [TangentWizard] different templates for different categories? In reply to
Thanks, I checked I had a look at this mod after you said it, but if Im reading it correctly it doesn't generate, static prepaired html, it generates the page each time with cgi, so this could be slow with lots of links?,
Maybe Im reading it wrong but, dynamic pages would be heavy on the system,

Thanks a million though....WinkCrazy
Quote Reply
Re: [$loth] different templates for different categories? In reply to
Um? No your looking at the wrong mod here here is the link to the mod I mean... http://cgi-resource.co.uk/pages/multcat2.shtml , there you are it's excellent mod but then so are all glennu's mods Smile

Hope this helps
TangentWizard Tongue