Gossamer Forum
Quote Reply
Loop Problem
I have a global that returns all the top level categories for display on any page.

I also use this in the category template:

<%set CN = $ID%>
<%TopL_Cats%>
<%loop TopLCats%>
<%if CN =1%><a href="<%URL%>" class="hlight"><%else%><a href="<%URL%>"><%endif%><%Name%></a>
<%endloop%>

What I'm trying to do is highlight the current category, but this only highlights ALL the category Names on that category page.

For example,

In the category page Computing I set the ID to CN.
The loop should see that CN = 1
Now the loop should use the class=hlight, else donít.

Does this makes sense because it doesn't work!

--------------------------------
Privacy Software

Last edited by:

BLOOD: Jan 19, 2006, 2:23 AM
Quote Reply
Re: [BLOOD] Loop Problem In reply to
Hi,

Please just use <%if CN ==1% or <%CN eq "1"%> will work.

cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Loop Problem In reply to
Thanks, but that isn't it because the highlighting is still on all the categories. Anyone else please help? This is the actual globat created by brewt.


sub {
my $category = $DB->table('Category');
$category->select_options('ORDER BY Name');
my $sth = $category->select;
my @cats;
while (my $cat = $sth->fetchrow_hashref) {
$cat->{URL} = "$CFG->{build_root_url}/" . $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";
push @cats, $cat;
}
return { TopLCats => \@cats };
}

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Loop Problem In reply to
Hi,

In this case, I think you can change the if condition to something like this

<%if first%> ...highlighting...<%else%>...no highlighting...<%endif%>

Hope that helps


Cheers,



Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [BLOOD] Loop Problem In reply to
Thanks, but using the category ID's will distinguish the category pages from each other which I think would be needed.

If this this cant work I could always handcode the categories like:

<%if ID = 1%><a class="hlight" href="/computing/">Computing</a><%else%><a href="/computing/">Computing</a><%endif%>

<%if ID = 2%><a class="hlight" href="/holidays/">Holidays</a><%else%><a href="/hoidays/">Holidays</a><%endif%>
etc...

But not as good of course Unsure

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Loop Problem In reply to
Are you sure, $ID is the category id?
I believe, not.
This is why I think it doesn't work.

Category id should be catid, or something similar...
You should check the original category.html comments.
There is described correctly.

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...
Quote Reply
Re: [webmaster33] Loop Problem In reply to
Yes $ID is fine or you can use $category_id (probably safer though). Still no joy - again ALL the category links are highlighted. Pirate

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Loop Problem In reply to
what is your LSQL version?

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...
Quote Reply
Re: [webmaster33] Loop Problem In reply to
Latest 3.04.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Loop Problem In reply to
Also note, if you SET CN outside the loop, it will have just a static value Wink

Try this:
Code:
<%TopL_Cats%>
<%loop TopLCats%>
<%set CN = $ID%>
<%if CN =1%>
<a href="<%URL%>" class="hlight"></a>
<%else%>
<a href="<%URL%>"><%Name%></a>
<%endif%>
<%endloop%>

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...
Quote Reply
Re: [webmaster33] Loop Problem In reply to
After much thought I have it.

<%set CN = $category_id%>
<%set NM = $Name%>

<%TopL_Cats%>
<%loop TopLCats%>

<a href="<%URL%>"><%if Name eq $NM and category_id = $CN%><span class="hlight"><%Name%></span><%else%><%Name%><%endif%></a>
<%endloop%>

Now when in a particular category, the corect category name will be highlighted.

PHEW! Cool

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Loop Problem In reply to
I might have misunderstood the problem...
Anyway, I'm glad you worked out!

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...