Forum

Thread tagged as: Question

dumb question re categories

Using latest Perch V2. Client has a number of items that they wish to assign to categories. Fine I can get them to assign an item to a category with the following in my item template

<perch:categories id="trainers" label="select trainer" set="trainers" required="true" display-as="checkboxes" />

How do I show the category in the html output?

How do I order items by category if I have several items from different categories displayed on output page?

I am sure this is simple but I cant find what I need in docs.

Many thanks

Charlie Elsey

Charlie Elsey 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Thanks Drew, I saw that. Maybe I am missing the blindingly obvious...

...But how do I actually show a category name on the output

so I have a set called 'trainers', within which there are categories eg reebok, nike, newbalance

so I might have a category reebok trainers

I want html output to show

reebok trainers

groovy shoes one

groovy shoes two etc

Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Charlie,

from the page Drew linked to, you need:

If you wish to output a list of categories to the page then you can use the perch:categories tag pair with your markup between the opening and closing tags.

<perch:categories id="trainers" label="select trainer" set="trainers" required="true" display-as="checkboxes">
  <perch:before>
    <ul>
  </perch:before>

  <li><perch:category id="catTitle" /></li>  // this loops through and shows all the categories that have been assigned

  <perch:after>
    </ul>
  </perch:after>
</perch:categories>

Thanks Duncan

I have two sets, colours and trainers

colour categories red, green, white etc

trainers categories reebok, nike, newbalance etc

I maybe am not being clear. I don't want a list of the categories themselves, I want to be able to show a list of items that are under a category, so eg all the 'red' items or all the 'reebok' items

Duncan Revell

Duncan Revell 78 points
Registered Developer

In that case, you're probably after these docs:

https://docs.grabaperch.com/perch/categories/filtering/

Duncan

Thank you very much, why couldn't I find those docs doh!