2

I've been trying to get this working but can't seem to find a solution.

I have two different types of Categories in a commerce project.

  • Level One
  • Level Two

Examples

  • Level One would be Mens, Ladies, Kids etc
  • Level Two would be T-Shirts, Jumpers, Shoes etc

When I click on 'Mens' on the navigation, it brings me to the Mens page, I then get a sub navigation on that page which shows me any Level Two categories that are related to the Level One category (Mens).

These are related by using the categories field type.

This is got easily by the following:

{% for subCat in craft.categories.group('levelTwo').relatedTo(category) %}

The problem that I encounter now, is when you click on one of the Level Two categories on that sub nav (T-Shirts for example), it brings me to the t-shirt category page. I want to be able to display the same sub nav that is on Level One (Mens), on the Level Two (T-shirts) page.

{% for subCat in craft.categories.group('levelTwo') %}

The above snippet shows me all the categories in Level Two, which is wrong.

I need to be able to show all the categories in Level Two, that have have the same categories field type. The handle of this categories field type is topLevelConnection.

Any suggestions would be greatly appreciated!

1 Answer 1

3

Turns out I was overthinking it, I was able to connect it with the following piece of code.

{% set levelOne = category.topLevelConnection %}
{% for subCat in craft.categories.group('levelTwo').relatedTo(levelOne) %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.