Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Category Template - Don't want subs to inherit

Quote Reply
Category Template - Don't want subs to inherit
Hey All!

I have a main category with a custom template on a links 3.0.3 install. All the sub-categories underneath that category inherit that template. I don't want them too. How do I go about just limiting the main category with that template and the subs under keep the old one?

Thanks
Chris
Quote Reply
Re: [Chrisp] Category Template - Don't want subs to inherit In reply to
One way of doing this would be to not use Category_Template, and do it in the templates. You could instead do something like:
Code:
<%if ID = 1234%><%include category_template.html%><%endparse%><%endif%>
at the top of the category.html template.

Adrian
Quote Reply
Re: [brewt] Category Template - Don't want subs to inherit In reply to
Thanks a ton Brewt!

Works great.

Chris
Quote Reply
Re: [brewt] Category Template - Don't want subs to inherit In reply to
Hi there, is there another solution to this problem? We have categories from A to Z which all use the navcategory.html template. There are perhaps several hundred of these (i.e Actors>A, Actors>B, Actresses>A, etc!) and therefore the solution above wouldn't be ideal. Can we alter the code to disable templates being inherited by sub-categories?

Someone suggested adding this to the navcategory.html template

<%if Category_Template and Category_Template ne 'navcategory.html'%><%include $Category_Template%><%endparse%><%endif~%>

But it doesn't seem to work.

JeffB
GT customer for 6 years (and counting!)

Last edited by:

jeffb: Oct 3, 2006, 6:30 AM
Quote Reply
Re: [jeffb] Category Template - Don't want subs to inherit In reply to
You'll probably want to remove the line:
<%if Category_Template and Category_Template ne 'navcategory.html'%><%include $Category_Template%><%endparse%><%endif~%>
from your templates anyways since it isn't needed (it was old template code that was left in).

There's currently no easy way to disable the inheritance, but it's on my todo list. In the meantime, You could just use what I suggested above for the upper level categories and clear out the Category_Template values for the categories.

Another thing you could do is create a new column and use that old line of template code at the top of your category.html template:
<%if COLUMNNAME%><%include $COLUMNNAME%><%endparse%><%endif~%>

Adrian

Last edited by:

brewt: Oct 3, 2006, 4:14 PM
Quote Reply
Re: [brewt] Category Template - Don't want subs to inherit In reply to
Thanks for the speedy reply Adrian. I thought that code was mine as it contained 'navcategory.html' which is the template I use for categories like "Actors" and "Actors > A", "Actors > B" etc. For the end category, i.e. "Actors > A > Ben Affleck' I wanted to use the standard category.html template as it was easier to specify a category for the 'drill down' categories rather then every final category. Not sure if that makes much sense in writing!

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] Category Template - Don't want subs to inherit In reply to
So you want to use one template for everything except for the leaf (in tree terminology) categories?

So for something like:
Code:
A
+-B
+-C
| +-D
| | --E
| --F
--G
--H
A, C, D, G would use one template and B, E, F, H would use another?

If that's the case, that that would be relatively easy to fix by writing a global that sees if the current category has any children. Something like:
Code:
sub {
my $cat_id = shift;
return $DB->table('Category')->count({ FatherID => $cat_id });
}
Then in the templates, do something like:
Code:
<%set children = children_count($ID)%>
<%if not children%><%include child_category.html%><%endparse%><%endif%>

Adrian
Quote Reply
Re: [brewt] Category Template - Don't want subs to inherit In reply to
Great, that should do the trick, thanks :)

JeffB
GT customer for 6 years (and counting!)