Can I add category names as style classes?

rhodes

Active member
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
 
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>
 
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.
 
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.
 
Top Bottom