Template Tags and Filters¶
django-adminlte2-templates template tags and filters that can be used by adding {% load adminlte2_tags %}
to your layout templates:
Tags¶
-
{% add_active %}
Add HTML class name
active
to sidebar and header navigation links based on comparison of given URL pattern with current URL.Parameters:
- url_pattern: (str) URL pattern for
reverse
matching - exact_match: (bool, optional) Toggle for exact matching. Defaults to
False
- not_when: (str, optional) Comma-separated string of patterns that will render comparison as
False
. Defaults to''
*args
and**kwargs
for URLreverse
matching
Example:
<li class="{% add_active 'app:page' object.pk %}"> <a href="{% url 'app:page' object.pk %}">Details</a> </li>
- url_pattern: (str) URL pattern for
-
{% gravatar_url %}
Generates a Gravatar URL based on the details of the current user.
For your convenience, you can also set the parameters related to {% gravatar_url %} in Django
settings.py
. Please check the Settings > Gravatar section for more information.To know more about Gravatar request parameters, please check the Gravatar Image Request documentation for more information.
Parameters:
- user: (User object, optional) User object, defaults to context
user
. - size: (int, optional) Image size. You may request images anywhere from
1
up to2048
, however note that many users have lower resolution images, so requesting larger sizes may result in pixelation/low-quality images. Defaults to80
. - default: (str, optional) Default Gravatar image to load. You can supply your own default image by supplying the URL to an image. Alternatively, you can use any of these valid values:
'404'
,'mp'
,'identicon'
,'monsterid'
,'wavatar'
,'retro'
,'robohash'
,'blank'
. Defaults to'mp'
. - force_default: (bool, optional) Toggle to force load default Gravatar image. Defaults to
False
. - rating: (str, optional) Gravatar image rating. Valid values are:
'g'
,'pg'
,'r'
,'x'
. Defaults to'pg'
.
Example:
<img src="{% gravatar_url %}" alt="User Avatar">
- user: (User object, optional) User object, defaults to context
-
{% paginator %}
Generates an HTML code block for ListView pagination. HTML code output is based on template layout
adminlte2/extras/paginator.html
.You can customize the output by overriding the aforementioned layout and using the template blocks provided. Please check the Template Blocks > Paginator section for more information.
Parameters:
- adjacent_pages: (int, optional) Adjacent page links to current page link. Defaults to
2
- align: (str, optional) Element alignment. Valid values are
'initial'
,'center'
,'left'
,'right'
. Defaults to'initial'
. - no_margin: (bool, optional) Toggle to remove margin around element. Defaults to
False
.
Example:
{% if is_paginated %} {% paginator adjacent_pages=2 align="center" no_margin=True %} {% endif %}
- adjacent_pages: (int, optional) Adjacent page links to current page link. Defaults to
Filters¶
-
add_class
Add HTML class names to a form field.
Example:
{% for field in form %} <div class="form-group {% if field.errors %}has-error{% endif %}"> {{ field.label_tag }} {% if field.errors %} <div class="text-danger"> {{ field.errors }} </div> {% endif %} {{ field|add_class:'form-control' }} {% if field.help_text %} <p class="help-block">{{ field.help_text|safe }}</p> {% endif %} </div> {% endfor %}