Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Possible bug in Category Template

Quote Reply
Possible bug in Category Template
Hi,

I just spent the last hour updating some of my categories to use a different category template - using the new field in Links 2.05 - called "Category Template".

I specified a new template (categorygen.html) for...

Actors and Actresses
and
Actors and Actresses/Actors
and
Actors and Actresses/Actors/B

but then for Actors and Actresses/Actors/B/Ben Affleck, I just left the Category Template field empty because I wanted it to use the standard template (category.html).

The problem is, that after a full build, the Ben Affleck page is being built using the categorygen.html template rather than the category.html template. Why is this? How do I stop this from happening?

JeffB

Quote Reply
Re: Possible bug in Category Template In reply to
Hi,

This is a feature, not a bug. Subcategories inherit the category of their parent (as otherwise you would need to edit every single subcategory).

You would need to edit Ben Affleck and put 'category.html' in the CategoryTemplate field.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Possible bug in Category Template In reply to
The problem with this feature is that I want a different category for my "child" than from its "parent". I have thousands of "children" but only a couple of parents. How can I change the code so that I can have 1 template for my parent and use category.html (i.e. leave it blank) for the children?

Thanks

JeffB

Quote Reply
Re: Possible bug in Category Template In reply to
Hi,

You'll need to edit Links/Category.pm sub _template_set. Basically you want to return '' if the get fails. Just delete the part that says look at the parents.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Possible bug in Category Template In reply to
Alex/Anyone,

Firstly - thank you for the solution. Here is the solution for anyone else that wants a different category for their parent and wants to use category.html for children categories.

Code:
sub _template_set {
# -------------------------------------------------------------------
# Returns the template set for a given category id.
#
my ($self, $id) = @_;
return unless ($id);

# If this category has a template set, use it.
my $cat_info = $self->get($id, 'HASH', 'Category_Template');
if ($cat_info->{Category_Template}) {
return $cat_info->{Category_Template};
}

# Otherwise look at it's parents.
# my $template = '';
# my $parents = $self->parents ($id);
# foreach my $parent (@$parents) {
# my $cat_info = $self->get($parent, 'HASH', 'Category_Template');
# if ($cat_info->{Category_Template}) {
# $template = $cat_info->{Category_Template};
# last;
# }
# }
# return $template;
}
Thanks

Quote Reply
Re: [Alex] Possible bug in Category Template In reply to
Hi,

We are now using LinksSQL 2.1.0 and the sub template_set inside Links/Category.pm has changed since we did the edit described above. Here is the new code for this sub routine...

sub template_set {
# -------------------------------------------------------------------
# Return the value of template set to use for a given category.
#
my $self = shift;
my $id = shift or return $self->error ('BADARGS', 'FATAL', "Must pass category id to template_set");
return '' unless (exists $self->{schema}->{cols}->{Category_Template});


return $self->{_template_cache}->{$id} if (exists $self->{_template_cache}->{$id});

# If this category has a template set, use it.
my ($cat_info) = $self->select ( ['Category_Template'], { ID => $id })->fetchrow_array;


# Otherwise look at it's parents.
unless ($cat_info) {
my $parents = $self->parents ($id);
foreach my $parent (@$parents) {
($cat_info) = $self->select ( ['Category_Template'], { ID => $parent })->fetchrow_array;
if ($cat_info) {
last;
}
}
}
$self->{_template_cache}->{$id} = $cat_info || '';
return $self->{_template_cache}->{$id};
}



I tried commenting out the following lines, but it did not work...

sub template_set {
# -------------------------------------------------------------------
# Return the value of template set to use for a given category.
#
my $self = shift;
my $id = shift or return $self->error ('BADARGS', 'FATAL', "Must pass category id to template_set");
return '' unless (exists $self->{schema}->{cols}->{Category_Template});


return $self->{_template_cache}->{$id} if (exists $self->{_template_cache}->{$id});

# If this category has a template set, use it.
my ($cat_info) = $self->select ( ['Category_Template'], { ID => $id })->fetchrow_array;


# Otherwise look at it's parents.
# unless ($cat_info) {
# my $parents = $self->parents ($id);
# foreach my $parent (@$parents) {
# ($cat_info) = $self->select ( ['Category_Template'], { ID => $parent })->fetchrow_array;
# if ($cat_info) {
# last;
# }
# }
# }
# $self->{_template_cache}->{$id} = $cat_info || '';
# return $self->{_template_cache}->{$id};
}



So, which lines in this new-look sub routine do I need to comment/delete in order to stop Links from using the category template of its parent directory?

If you don't understand then please start at the top of this read and all should become clear!

Regards

JeffB.

Last edited by:

jeffb: May 1, 2002, 7:20 AM
Post deleted by Paul In reply to
Quote Reply
Re: [Alex] Possible bug in Category Template In reply to
I see problem of jeffb, especially if he has 50-100 subcategories in second level below a root folder. He should change all of them manually, to have inherited tempates in them & below them, but not the inherited from the root category.

A possible solution could be to be able to define the following properties for a node:
- category template for current node
- category template for childerns of current node

This will allow jeffb to set the category template for childrens right from the root categories.

Opinions?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: May 2, 2002, 5:06 AM
Quote Reply
Re: [webmaster33] Possible bug in Category Template In reply to
All I need to do is to edit the code above. Unfortunately it has changed and I need to know which lines now need editing. I was hoping that Alex or someone else with a good understand of Links could easily tell me which lines they were.

This should be fairly easy Crazy

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] Possible bug in Category Template In reply to
Hi,

You should just be able to comment out:

Code:
# Otherwise look at it's parents.
unless ($cat_info) {
my $parents = $self->parents ($id);
foreach my $parent (@$parents) {
($cat_info) = $self->select ( ['Category_Template'], { ID => $parent })->fetchrow_array;
if ($cat_info) {
last;
}
}
}


those lines (that's what looks up the parents template set).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Possible bug in Category Template In reply to
Alex,

As I explained a couple of postings above - that doesn't work Frown

There must be something else I need to do, I was hoping you would know Unsure

JeffB.

My sub_template now looks like this...


Code:
sub template_set {
# -------------------------------------------------------------------
# Return the value of template set to use for a given category.
#
my $self = shift;
my $id = shift or return $self->error ('BADARGS', 'FATAL', "Must pass category id to template_set");
return '' unless (exists $self->{schema}->{cols}->{Category_Template});

return $self->{_template_cache}->{$id} if (exists $self->{_template_cache}->{$id});

# If this category has a template set, use it.
my ($cat_info) = $self->select ( ['Category_Template'], { ID => $id })->fetchrow_array;

# Otherwise look at it's parents.
# unless ($cat_info) {
# my $parents = $self->parents ($id);
# foreach my $parent (@$parents) {
# ($cat_info) = $self->select ( ['Category_Template'], { ID => $parent })->fetchrow_array;
# if ($cat_info) {
# last;
# }
# }
# }
$self->{_template_cache}->{$id} = $cat_info || '';
return $self->{_template_cache}->{$id};
}


JeffB
GT customer for 6 years (and counting!)

Last edited by:

jeffb: May 12, 2002, 4:58 PM
Quote Reply
Re: [jeffb] Possible bug in Category Template In reply to
Hi,

What doesn't work? Your first example commented out too many extra lines. You need the last two lines uncommented.

What happens now?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Possible bug in Category Template In reply to
Even when I don't comment out the last 2 lines, the parents category is still being imposed on the child. This has only happened since I moved to the latest version of LinksSQL and it's due to the changes in the code (as shown above).

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] Possible bug in Category Template In reply to
Are you running under mod_perl/speedycgi? Did you restart if you were?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Possible bug in Category Template In reply to
In Reply To:
This is a feature, not a bug.

Alex, you're beginning to sound like Microsoft. Tongue

Sean
Quote Reply
Re: [SeanP] Possible bug in Category Template In reply to
Spot on Cool

After re-starting apache and it reloading the mod_perl it seems to work fine. Thanks for the help and sorry for not thinking of this earlier!

Now, if we can just have GT community ...Wink

JeffB
GT customer for 6 years (and counting!)