I'm trying to pull out selected categories in a front-end user profile. The cats have 2 levels and need to be pulled out into a nested list with only the selected options. I've tried different ways of doing this but nothing seems to work by using one for loop. So have nested the second level cats in a second for loop. This will work but the loop.first and loop.last variables are using the parent for loop and not the nested one? Or is there a better/easier way of doing this?
{% for challenge in user.challenges.level(1).options %}
<li>
{{ challenge.title }}
{% for child in user.challenges.level(2).options %}
{% if child and child.getParent().id == challenge.id %}
{% if loop.first %}<ul>{% endif %}
<li>{{ child.title }}</li>
{% if loop.last %}</ul>{% endif %}
{% endif %}
{% endfor %}
</li>
{% endfor %}