Types of Tags

Function tags

native_tags.nodes.do_function(parser, token)

Performs a defined function on the passed arguments. Normally this returns the output of the function into the template. If the second to last argument is as, the result of the function is stored in the context and is named whatever the last argument is.

Syntax:

{% [function] [var args...] [name=value kwargs...] [as varname] %}

Examples:

{% search '^(\d{3})$' 800 as match %}

{% map sha1 hello world %}

Comparison tags

native_tags.nodes.do_comparison(parser, token)

Compares passed arguments. Attached functions should return boolean True or False. If the attached function returns True, the first node list is rendered. If the attached function returns False, the second optional node list is rendered (part after the {% else %} statement). If the last argument in the tag is negate, then the opposite node list is rendered (like an ifnot tag).

Syntax:

{% if_[comparison] [var args...] [name=value kwargs...] [negate] %}
    {# first node list in here #}
{% else %}
    {# second optional node list in here #}
{% endif_[comparison] %}

Supported comparisons are match, find, startswith, endswith, less, less_or_equal, greater and greater_or_equal and many more. Checkout the Contrib Add Ons for more examples

Examples:

{% if_less some_object.id 3 %}
{{ some_object }} has an id less than 3.
{% endif_less %}

{% if_match request.path '^/$' %}
Welcome home
{% endif_match %}

Block tags

native_tags.nodes.do_block(parser, token)

Process several nodes inside a single block Block functions take context, nodelist as first arguments If the second to last argument is as, the rendered result is stored in the context and is named whatever the last argument is.

Syntax:

{% [block] [var args...] [name=value kwargs...] [as varname] %}
    ... nodelist ...
{% end[block] %}

Examples:

{% render_block as rendered_output %}
    {{ request.path }}/blog/{{ blog.slug }}
{% endrender_block %}

{% highlight_block python %}
    import this
{% endhighlight_block %}

Filter tags

Native Filter tags are pretty much the same as regular Django filter tags. There is no special sauce here because the arguments that you can pass filter tags is very limited and is currently being expanded in this issue. Filters take the piped value as the first argument and as of now only one extra argument like so:

{{ value|filter:arg }}

Table Of Contents

Previous topic

Change Log

Next topic

Features of Native Tags

This Page