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

Discussion in 'Resource Manager Support' started by rhodes, Apr 15, 2014.

  1. rhodes

    rhodes Active Member


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


    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
  2. Chris D

    Chris D XenForo Developer Staff Member

    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:
    <xen:container var="$bodyClasses">category-{$category.category_id}</xen:container>
  3. rhodes

    rhodes Active Member

    Great! Thank you very much @Chris D .
  4. rhodes

    rhodes Active Member

    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.
  5. Chris D

    Chris D XenForo Developer Staff Member

    Putting this in your template:
    <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.
  6. rhodes

    rhodes Active Member

    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.
    Chris D likes this.

Share This Page