Forum

Thread tagged as: Question, Runway

Runway category loop

Does anyone know if there a way of looping through specific categories in Runway?

For example, I've created the following categories in 'Set A':

Category A
  Sub Cat 1 of A
  Sub Cat 2 of A
Category B
Category C

perch_categories(); will obviously loop through ALL categories in a nice nested list. Is there a way of only displaying/selecting level 1 categories - so return Category A, B and C, but exclude Sub Cats of A?

Darren Neasham

Darren Neasham 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You may be able to test catParentID - it should be 0 if it's a top level cat.

<perch:if id="catParentID" match="eq" value="0">
   ... this is a top level category ...
</perch:if>

Works perfectly. That's great, thanks.

Can I use the same approach for showing only Sub Cats? So, if I was on Category A page, only loop through Sub Cats of A, excluding Category B and C?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to match the path. Set the path of the parent you want to select from the page:

PerchSystem::set_var('selectedCat', 'foo/category-a');  // or use perch_get('cat') or whatever

Then in your template:

<perch:if id="catPath" match="contains" value="{selectedCat}">

</perch:if>

Excellent, thanks.