{% for category in categories.iteritems() %}
<table class="table table-bordered">
    <thead class="categoryhead">
        <tr>
            <td colspan="5">
                <div><strong><a href="{{ category[0].url }}">{{ category[0].title }}</a></strong></div>
            </td>
        </tr>
    </thead>
    <tbody class="forumbody">
        <tr class="forum_stats">
            <td colspan="2"><strong>Forum</strong></td>
            <td width="85" align="center" style="white-space: nowrap"><strong>Topics</strong></td>
            <td width="85" align="center" style="white-space: nowrap"><strong>Posts</strong></td>
            <td width="200" align="center" style="white-space: nowrap"><strong>Last Post</strong></td>
        </tr>

        {% for forum in category[1] %}
        <tr>
            <td align="center" valign="center" width="4%">

            {% if forum[0].external %}
                <span class="fa fa-external-link" style="font-size: 2em"></span>
            </td>

            <td valign="top">
                <strong><a href="{{ forum[0].external }}">{{ forum[0].title }}</a></strong>

                <div class="forum-description">
                    {% autoescape false %}
                    {{ forum[0].description|markup }}
                    {% endautoescape %}
                </div>
            </td>

            <td valign="top" align="center" style="white-space: nowrap">-</td>
            <td valign="top" align="center" style="white-space: nowrap">-</td>
            <td valign="top" align="right" style="white-space: nowrap">-</td>
            <!-- End external -->
            {% else %}

            {% if forum[0].locked %}
                <span class="fa fa-lock" style="font-size: 2em"></span>
            {% elif forum[0]|forum_is_unread(forum[1], current_user) %}
                <span class="fa fa-comments" style="font-size: 2em"></span>
            {% else %}
                <span class="fa fa-comments-o" style="font-size: 2em"></span>
            {% endif %}

            </td>

            <td valign="top">
                <strong><a href="{{ forum[0].url }}">{{ forum[0].title }}</a></strong>

                <div class="forum-description">
                    {% autoescape false %}
                    {{ forum[0].description|markup }}
                    {% endautoescape %}
                    {% if forum[0].show_moderators %}
                    <div class="forum-moderators">
                        Moderators:
                        {% for moderator in forum[0].moderators %}
                        <a href="{{ url_for('user.profile', username=moderator.username) }}">{{ moderator.username }}</a>{% if not loop.last %}, {% endif %}
                        {% endfor %}
                    </div>
                    {% endif %}
                </div>
            </td>

            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].topic_count }}</td>
            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].post_count }}</td>

            <td valign="top" align="right" style="white-space: nowrap">
                {% if forum[0].last_post_id %}
                <a href="{{ forum[0].last_post.url }}" title="{{ forum[0].last_post.topic.title }}">
                    <strong>{{ forum[0].last_post.topic.title|crop_title }}</strong>
                </a>
                <br />
                {{ forum[0].last_post.date_created|time_since }}<br />

                    {% if forum[0].last_post.user_id %}
                    by <a href="{{ url_for('user.profile', username=forum[0].last_post.user.username) }}">{{ forum[0].last_post.user.username }}</a>
                    {% else %}
                    {{ forum[0].last_post.username }}
                    {% endif %}

                {% else %}
                No posts
                {% endif %}
            {% endif %}
            </td>
        </tr>
        {% endfor %}

    </tbody>
</table>
{% endfor %}
