• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Can I add category names as style classes?

rhodes

Active member
#1
Hello,

I use XF1.3 and resource manager and I'm really happy with this combination.

Now I would like to add some styling for category listings (hide/show elements).

Example:

I have two categories cat-1 and cat-2.
Resources of type cat-1 are listed here: /community/cat-1/
Resources of type cat-2 are listed here: /community/cat-2/

Is it possible to add the category name as style class to the body element of the category listing page
(<body class="cat-1">) so that I could use this class as a selector for my styling?

Regards, rhodes
 

Chris D

XenForo developer
Staff member
#2
You probably should add the category IDs to the body classes rather than the titles. Category titles would look like "This is a category title" and that doesn't translate well into a usable CSS selector.

So add something like this to your resource_category template:
Code:
<xen:container var="$bodyClasses">category-{$category.category_id}</xen:container>
 

rhodes

Active member
#4
I'm confused, sorry. So
<xen:container var...> defines a variable available within my template.

<xen:container var="$bodyClasses">category-{$category.category_id}</xen:container>

But how can I now print $bodyClasses within my template?

<div class="oldstyles {$bodyClasses}" (is wrong ;) , of course)

Sorry I'm not too experienced with xenforo template syntax. I already searched for xen tag syntax, but cannot find sth. suitable.
 

Chris D

XenForo developer
Staff member
#5
Putting this in your template:
Code:
<xen:container var="$bodyClasses">category-{$category.category_id}</xen:container>
Does exactly what you requested in your original post.

It adds whatever is in that variable as class assigned to the body tag.

Once you add that code to your template, view the source of the page and you will see your class in the <body> tag.
 

rhodes

Active member
#6
Yes, you're right. My fault. I was searching to the bottom, but did not realize that the style class already was added to the body tag. Solved my problem. Thank you.