{% with id=widget.attrs.id %}
<ul{% if id %} id="{{ id }}"{% endif %}{% if widget.attrs.class %} class="{{ widget.attrs.class }}"{% endif %}>
  {% for group, options, index in widget.optgroups %}
    {% if group %}
    <li>{{ group }}
      <ul{% if id %} id="{{ id }}_{{ index }}"{% endif %}>
    {% endif %}

      {% for option in options %}
        <li>
          {% include option.template_name with widget=option %}
            {% if option.permissions %}
            <p class="help" style="margin-bottom: 25px;">
            {% for perm in option.permissions %}
              <small>{{ perm }}{% if not forloop.last %}&nbsp;<b>|</b>&nbsp;{% endif %}</small>
            {% endfor %}
            {% endif %}
            </p>
        </li>
      {% endfor %}

    {% if group %}
      </ul>
    </li>
    {% endif %}
  {% endfor %}
</ul>
{% endwith %}
