{#
Displays a tree of organzations

NB This template can be slow because it is recursive and uses link_for. At
DGU we speeded up display of the tree 10 times (necessary as we have 1000
organizations) by replacing this template with a recursive code routine:
https://github.com/datagovuk/ckanext-dgu/blob/5fb78b354517c2198245bdc9c98fb5d6c82c6bcc/ckanext/dgu/lib/helpers.py#L140

orgs    - List of organizations

Example:

{% snippet 'organization/snippets/organization_tree.html', top_nodes=h.group_tree(type_='organization'), use_longnames=False %}

#}

{% set type = 'asset' if h.ckan_version().split(".")[1]|int >= 9 else 'resource' %}

{% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}

<ul class="hierarchy-tree-top">
  {% for node in top_nodes recursive %}
      {% set longname = h.group_tree_get_longname(node.name) %}
      {% set display_text = node.title %}
      {% if use_longnames and longname%}
          {% set display_text = longname + " (" + display_text + ")" %}
      {% endif %}
      {% if node.highlighted %}
          <li class="highlighted" id="node_{{ node.name }}">
      {% else %}
          <li id="node_{{ node.name }}">
      {% endif %}
      {% link_for display_text, controller='organization', action='read', id=node.name %}
      {% if node.children %}
        <ul class="hierarchy-tree"> {{ loop(node.children) }} </ul>
      {% endif %}
    </li>
  {% endfor %}
</ul>
