Menu

This plugin is used to generate simple menus.

Installation

# settings.py

PLUGINS = [
    'flamingo.plugins.Menu',
]

Usage

# settings.py

MENU = [
    ['Section 1', [
        ['Article 1', 'section-1/article-1.rst'],
        ['Article 2', 'section-1/article-2.rst'],
    ],
    ['Section 2', [

        # menu items can contain queries
        # but have to return exactly one content object
        ['Article 3', {'path__endswith': 'article-3.rst'}],
    ]
]

This example shows how to generate a Bootstrap4 compliant menu

<!-- theme/templates/menu/bootstrap4.html -->
{% if not level %}
  {% set level=0 %}
{% endif %}
{% if not menu %}
  {% set menu=context.settings.MENU.main %}
{% endif %}
{% if is_dict(menu) %}
  {% set menu=menu.main %}
{% endif %}
{% for name, item in menu %}
  {% if is_list(item) %}
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ name }}</a>
      <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        {% with menu=item, level=level+1 %}
          {% include "menu/bootstrap4.html" %}
        {% endwith %}
      </div>
    </li>
  {% else %}
    {% if level == 0 %}
      <a class="nav-link" href="{{ item.url }}">{{ name }}</a>
    {% else %}
      <a class="dropdown-item" href="{{ item.url }}">{{ name }}</a>
    {% endif %}
  {% endif %}
{% endfor %}
<!-- base.html -->

{% extends "DEFAULT_TEMPLATE" %}

<div class="collapse navbar-collapse" id="navbarSupportedContent">
  <ul class="navbar-nav mr-auto">
    {% include "menu/bootstrap4.html" %}
  </ul>
</div>