Gossamer Forum
Home : Products : Gossamer Links : Discussions :

category_name question

Quote Reply
category_name question
Hi,

Is there an easy way to reverse the order in which the variable category_name is put together?

For example:

If the directory structure is:

Dogs > Big Dogs > Sheperds

The category_name variable will spit out: Dogs/Big Dogs/Sheperds

I would like to display this is reverse order:

Sheperds/Big Dogs/Dogs

Thanks,

K
Quote Reply
Re: [kajukenbokid] category_name question In reply to
You can use the title_loop for the names, but since you can't loop through an array backwards yet (you will be able to in the next version), you'll need to write a global to do it for you.

Adrian
Quote Reply
Re: [brewt] category_name question In reply to
Can you hint/show me what the code would be for such a global - I'm not a Perl developer.

Does PERL have a 'reverse' function for array sorting?

Thanks,
K
Quote Reply
Re: [kajukenbokid] category_name question In reply to
Something like:
Code:
sub {
my $vars = GT::Template->vars;
my $title = $vars->{title_loop};
return unless ref $title eq 'ARRAY';
my @reversed = reverse @$title;
# Remove Home
pop @reversed;
return join("/", map { $_->{Name} } @reversed);
}

Adrian

Last edited by:

brewt: Apr 26, 2006, 4:06 PM
Quote Reply
Re: [brewt] category_name question In reply to
Hi,

I tried wrapping your code inside a sub and I got an undefined var error.

If I just declare the code within a global, the engine just spits out a string:


my $vars = GT::Template->vars;
my $title = $vars->{title_loop};
my @reversed = reverse @$title;
# Remove Home
pop @reversed;
return join("/", map { $_->{Name} } @reversed);

How can I use this within the context of a global?
Quote Reply
Re: [kajukenbokid] category_name question In reply to
This is exactly the error I am getting:

A fatal error has occured:
Can't use an undefined value as an ARRAY reference at (eval 20) line 4.



Seems to be a variable scope thing ..? Again, I don't know PERL.

Any help would be appreciated.

K
Quote Reply
Re: [kajukenbokid] category_name question In reply to
Sorry, I forgot to put it in a sub {}, try it again.

Adrian
Quote Reply
Re: [brewt] category_name question In reply to
I did and I got this error.

Any ideas.
Quote Reply
Re: [kajukenbokid] category_name question In reply to
Which template are you using it on?

Adrian
Quote Reply
Re: [brewt] category_name question In reply to
Hi,

I just inserted the global in the right sidebar template.
Quote Reply
Re: [kajukenbokid] category_name question In reply to
Considering that not every template has the title_loop tag (only category pages have it), you need to put a condition to restrict the usage of that tag.

Adrian
Quote Reply
Re: [brewt] category_name question In reply to
Cool.

I applied it in the category template and it worked fine.

-

Quick question: How would one force the script to return only the last two items inserted into the array?

The reason: I have a deep directory that starts at the continent, and goes right down to the city, and I don't want to have a huge page <title> - if you know what I mean...?

Esssentially, I would like to have the array keep only that last two items:

Pseudo code:

sub checkCount() {
if (array.count > 2) {
pop;
checkCount();
} else {
return array;
}

}

So in geo targetted directory, when a user is on the city level, all that would be left in the array is the City and State.

Makes sense?

I appreciate you PERL coders helping me out.

K