I'm looking to use multiple category group as a navigation. The categories have 3 levels and will be listed depending on set variable. I can list all categories in the group with the following:
{% set categories = craft.categories.group('categories') %}
<ul>
{% nav category in categories %}
<li>
<a href="{{ category.slug }}">{{ category.title }}</a>
{% ifchildren %}
<ul>{% children %}</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
However I would like to list only the third level categories after the top level and secondary level have been set. I've tried playing around with descendantOf but to no avail. Any help to point me in the right direction much appreciated.
---Final code---- After @damon input below this is what I ended up with more or less the same:
{# ---- Set Default Segment ---- #}
{% set segment = 'default' %}
{# ---- If url segment is set, set segment to it ---- #}
{% if craft.request.getSegment(2) %}
{% set segment = craft.request.getSegment(2) %}
{% endif %}
{% set cat = craft.categories.group('categories').slug(segment).first() %}
{% for categories in craft.categories.group('categories').descendantOf(cat).level(2) %}
{% if categories.getDescendants().total() != 0 %}
{% for category in craft.categories.group('categories').descendantOf(categories.id).level(3) %}
...
{% endfor %}
{% endif %}
{% endfor %}