{% for tab in tabs %}
{% if tab.selected and tab.id == tab.selected %}
{% elif not tab.selected and forloop.first %}
{% else %}
{% endif %}
{% endfor %}
{% for tab in tabs %}
{% if not tab.selected and forloop.first %}
{% elif tab.selected and tab.selected == tab.id %}
{% else %}
{% endif %}
{% if tab.content_template %}
{% include tab.content_template|template:theme %}
{% elif tab.content_template_name %}
{% include tab.content_template_name %}
{% else %}
{{ tab.content }}
{% endif %}