Templates Tags and Filters

Nuit provides a handlful of template tags and filters designed to abstract some of the complexities of writing templates for the framework.

Tags

extend

Extends another template, passing any keyword arguments to the parent template (prefixed by nuit_). For example:

{% extend 'nuit/base.html' topbar=True %}

results in the variable nuit_topbar being available (and set to True) in nuit/base.html.

app_menu

Renders the main application menu. Intended for use in the right_menu block, and should be filled with menu_item links. One optional argument:

title

The title of the application - displayed above the menu items.

Example usage:

{% block left_menu %}
    {% app_menu 'My Application' %}
        {% menu_item name='Page One' link='/page-one/' %}
        {% menu_item name='Page Two' link='/page-two/' %}
        {% menu_item name='Page Three' link='/page-three/' %}
        {% menu_item name='Page Four' link='/page-four/' %}
        {% menu_item name='Page Five' link='/page-five/' %}
    {% end_app_menu %}
{% endblock %}

set_active_menu

Renders an invisible element used by Javascript to set the active class on a menu item for this page. This must be within a template block that renders to the screen - it doesn’t matter which one. It produces no visible output. The only required attribute is:

active_menu

The unique ID of the menu item to be activated. To highlight the menu item in the example above, the required code would be:

{% set_active_menu "my-url" %}

pagination_menu

Used internally by Nuit in the nuit/generic/list.html template to generate the pagination links for a paginated list of objects. The required attributes are:

page_obj

The Django Page object for the current view of data. This is provided by Django’s ListView and Nuit’s SearchableListView.

show_totals
Default:True

Whether to show the total number of objects or not.

foundation_form

Renders a form using Foundation’s form styles in the given layout. Takes one required arguement, and one optional:

form

The Django Form object. Works with all standard Django Form classes.

csrf_enabled
Default:True

Whether to include the CSRF token or not.

collapse_container
Default:False

Whether to collapse the side padding of the form elements.

Further options are specified between the foundation_form and end_foundation_form tags. For more details, see the Forms documentation. Example usage:

{% foundation_form my_form_object %}
    title, first_name, surname
    email_address
{% end_foundation_form %}

Filters

message_class

Given a message object from Django’s django.contrib.messages, returns a string containing the CSS alert-box class for Foundation alert boxes corresponding to the message’s level (DEBUG, INFO, SUCCESS, WARNING or ERROR). Used to style the message alert boxes:

{% for message in messages %}
    <div data-alert class='alert-box {{message|message_class}}'>{{message}}</div>
{% endfor %}