<ul class="cat-module list-unstyled">
  {% for category in categories %}
  {% if category.category_id == category_id %}
  <li><a href="{{ category.href }}" class="head active">{{ category.name }}</a></li>
  {% if category.children %}
  {% for child in category.children %}
  <li><a href="{{ child.href }}" class="mright {{ child.category_id == child_id ? 'active'}} {{ child.category_id == last ? 'open'}} {{ last }}">{{ child.name }}</a></li>
  {% for child2 in child.children2 %}
  <li><a href="{{ child2.href }}" class="mright mright2 {{ child2.category_id == child2_id ? 'active'}} {{ child2.category_id == last ? 'open'}} {{ last }}">{{ child2.name }}</a></li>
  {% endfor %}
  {% endfor %}
  {% endif %}
  {% else %}
  <li><a href="{{ category.href }}" class="head">{{ category.name }}</a></li>
  {% endif %}
  {% endfor %}
</ul>