Default Tags

Default tags.

load name
{% load foo.bar.baz %}

Loads template library name.

The name is treated as a python import path, and the loaded module is expected to have a ‘register’ member, being an instance of :library:Library

extends name
{% extends base.html %}

Make this Template class extend the template in name

super name
{% super blockname %}

Renders the contents of blockname from the parent template.

block name
{% block foo %}
...
{% endblock %}

Declares a new overridable block in the template.

This will result in a new method on the class of the same name, so names must be valid Python identifiers.

if expr

Implements a simple if conditional.

{% if ...expr... %}
...
{% endif %}

Optionally, it may contain an else:

{% if ...expr... %}
...
{% else %}
...
{% endif %}
knights.tags.for()
{% for a in sequence %}
...
{% endfor %}

A python compatible {% for %} tag.

{% for a, b, c in foo.get(other=1) %}
...
{% endfor %}

The target values will be stacked on the scope for the duration, and removed once the loop exits.

Also you can provide an ‘empty’ block for when the list is empty.

{% for a in sequence %}
...
{% empty %}
sequence is empty
{% endfor %}
knights.tags.include()

Include another template in situ, using the current context.

{% include "othertemplate.html" %}

Optionally, you can update the context by passing keyword arguments:

{% include "other.html" foo=1, bar=baz * 6 %}
knights.tags.with()

Temporarily augment the current context.

{% with ...kwargs... %}
...
{% endwith %}