Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-03-21 13:24:35

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

category_list not setting active_class

Have an 4.08 install with the following code:

<txp:category_list section="photos" wraptag="ul" active_class="active" break="li" exclude="Article-images,Retired,site-design,slideshow" type="image">
<txp:category link="1" title="1" />
</txp:category_list>

I am finding the active_class is not getting set if I click on the resulting category link – for example, the following output is from the category page:

<ul class="category_list">
	<li>
<a href="http://localhost:8888/sta_v3/photos/?c=Facilities">Facilities</a>
</li>
	<li>
<a href="http://localhost:8888/sta_v3/photos/?c=Training">Training</a>
</li>
</ul>

Offline

#2 2009-03-21 13:37:01

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: category_list not setting active_class

Don’t know if it’s related to your problem, but I notice you are using capitals in category names, which should be avoided.

Offline

#3 2009-03-21 13:52:23

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: category_list not setting active_class

Hi Els,

Not the problem I’m afraid. The category names are now all lower case, and the resulting output is: (when in the “facilities” category page)

<ul class="category_list">
	<li>
<a href="http://localhost:8888/sta_v3/photos/?c=facilities">Facilities</a>
</li>
	<li>
<a href="http://localhost:8888/sta_v3/photos/?c=training">Training</a>
</li>
</ul>

Offline

#4 2009-03-21 14:15:25

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: category_list not setting active_class

Well, it was worth a try.
I can reproduce this behaviour when using category_list as a container tag, it does set the active_class however when used as a single tag…

Edit: I wonder if it’s related to this bug? But that was fixed in 4.0.8…

Last edited by els (2009-03-21 14:23:41)

Offline

#5 2009-03-21 20:52:00

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: category_list not setting active_class

The “active_class” is not applied by the code to a wraptag context, and that appears to be by design. The same functionality must needs be coded within the enclosed tag arrangement to accomplish the same task.

Offline

#6 2009-03-22 07:43:39

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: category_list not setting active_class

Thanks Rick. Here is the corrected code for anyone following along:

<txp:category_list section="photos" wraptag="ul" class="category_list" break="" exclude="article-images,retired,site-design,slideshow" type="image">
<li <txp:if_category name='<txp:category />'>class="active"</txp:if_category>>
<txp:category link="1" title="1" /></li>
</txp:category_list>

Offline

#7 2010-03-08 10:41:01

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 99

Re: category_list not setting active_class

Related.

This refuses to assign the class to the ‘a’ tag in a individual article context as it does in an article list, and I need it to:

<txp:category_list section="projects" wraptag="ul" class="sidebar-menu" break="li" active_class="active_trail" />

My answer – it may not be pretty but might be handy for others who ever have a spot of bother with this. I tried about 6 permutations and mayhem with quotes before arriving at it.

<txp:category_list section="projects" wraptag="ul" class="sidebar-menu">
      <li>
        <txp:category title='1' link='1' class='<txp:asy_wtag><txp:if_article_category number="1" name="<txp:category />">active_trail</txp:if_article_category></txp:asy_wtag>' />
      </li>
    </txp:category_list>

It only works when the query is inside the class quotes, and with that magical asy_wtag.

TXP 4.2.0

Offline

#8 2010-03-08 10:51:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: category_list not setting active_class

peterj wrote:

mayhem with quotes

Yeah, it gets hairy doesn’t it! An (untested) alternative without asy_wondertag:

<txp:category title="1" link="1" class='<txp:if_article_category number="1" name=''<txp:category />''>active_trail</txp:if_article_category>' />

Note the pair of apostrophes surrounding the <txp:category /> tag, not double quotes. This tells the tag parser that the first apostrophe is not really the end of the “outer” class attribute but that it should ‘escape’ the apostrophe and carry on parsing. Further reading on the subject for bamboozling purposes only :o)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2010-03-08 12:06:55

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 99

Re: category_list not setting active_class

Thanks Bloke. Tested that and it does work. Next thing is to try to remmber that rule!

Offline

#10 2011-01-23 20:26:04

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,091
Website Mastodon

Re: category_list not setting active_class

i have tried the suggested fix but to no avail. I am unable to get active class to work. So close and yet…

<txp:category_list parent="products" exclude="products" children="0" wraptag="ul" break=""> <li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>><txp:category title="1" link="1" /></li> </txp:category_list>

In my template page i have :

<ul id="subnav_products">  
   <txp:category_list parent="products" exclude="products" children="0" wraptag="ul" break="">
	<li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>><txp:category title="1" link="1" /></li>
	</txp:category_list> 
</ul>

The only thing i need to have what i ideally want: a simple way to use categories to have sub-sections tied to articles. so sweet!
I arrange the sub-sections by assigning them to a parent category then outputting them by parent,
thanks to this tip !!


…. texted postive

Offline

#11 2011-01-23 20:43:39

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: category_list not setting active_class

You have a double <ul>, but I don’t think that is the reason it doesn’t work. The only reason I can think of is that somehow there is no category context, so the conditional returns false. Have you looked at the tag trace?

Offline

#12 2011-01-23 20:49:57

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,091
Website Mastodon

Re: category_list not setting active_class

hi. the first UL is needed ‘cause if i delete it nothing readable shows up although there are links there that i can click on… just can’t see them.

How do i do “tag trace”?

Last edited by bici (2011-01-23 20:51:48)


…. texted postive

Offline

Board footer

Powered by FluxBB