{% macro navbar() -%}
    {% if lw_navbar %}
<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container-fluid">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <a class="brand" href="{{ lw_navbar.get_brand().brand_url }}">
                {% if lw_navbar.get_brand().brand_html %}{{ lw_navbar.get_brand().brand_html|safe }}{% endif %}
                {% if lw_navbar.get_brand().brand_name %}{{ lw_navbar.get_brand().brand_name }}{% endif %}
            </a>
            <div class="nav-collapse collapse">
                {% if lw_navbar.get_data().profile %}
                <ul class="nav pull-right">
                    <li class="divider-vertical"></li>
                    {{ navbar_items(lw_navbar.profile, 'pull-right') }}
                </ul>
                {% endif %}
                {% if lw_navbar.get_data().items %}
                <ul class="nav">
                    {{ navbar_items(lw_navbar.menu) }}
                </ul>
                {% endif %}
            </div>
        </div>
    </div>
</div>
    {% endif %}
{%- endmacro %}

{% macro navbar_items(items, pull='') -%}
    {% for item in items if not item.hidden %}
<li class="{% if item.active %}active {% endif %}{% if item.dropdown|length > 0 %}dropdown {% endif %}">
    {% if item.group %}
    <div class="btn-group {{ pull }}">
        {% for gitem in item.group %}
        {{ navbar_link(gitem, 'btn') }}
        {% endfor %}
    </div>
    {% else %}
    {{ navbar_link(item) }}
    {% endif %}
</li>
    {% endfor %}
{%- endmacro %}

{% macro navbar_link(item, class='') -%}
    {% if item.dropdown|length > 0 %}
<a href="{{item.url}}" data-toggle="dropdown" class="{{ class }} dropdown-toggle">{{ navbar_link_body(item) }}</a>
<ul class="dropdown-menu">
    <li>
        {% for ditem in item.dropdown if not ditem.hidden %}
        {{ navbar_link(ditem, class) }}
        {% endfor %}
    </li>
</ul>
    {% else %}
<a href="{{item.url}}" title="{{item.label}}" class="{{ class }}">{{ navbar_link_body(item) }}</a>
    {% endif %}
{%- endmacro %}

{% macro navbar_link_body(item) -%}
{% if item.icon %}<i class="{{item.icon}}"></i>{% endif %}{% if not item.only_icon %}{% if item.icon %} {% endif %}{{item.label}}{% endif %}{% if item.caret %}<span class="caret"></span>{% endif %}
{%- endmacro %}
