Comment on page
Template tags
Misago defines plenty of custom tags and filters for use by template authors.
This tag accepts same arguments as default `
tag from Django, except it uses the
MISAGO_ADDRESS` setting to render the absolute URL suitable for using in e-mails.There are situations when you want to slice list of items in template into sublists, e.g. when displaying grid of items in HTML it makes more sense to split iteration into two steps: iteration over rows and items in each row.
misago_batch
provides two simple and lazy filters that enable you to do this:Takes one argument, integer individual batch's length, then turns big list into list of lists.
{% load misago_batch %}
{% for row in user_profiles|batch:4 %}
<div class="row">
{% for profile in row %}
<div class="col-md-3">
{% include "card.html" %}
</div>
{% endfor %}
</div>
{% endfor %}
Works same as
batch
filter, but with one difference:If last batch length is shorter than requested, it fills it with
None
to make it requested length.{% load misago_batch %}
{% for row in user_profiles|batchnonefilled:4 %}
<div class="row">
{% for profile in row %}
<div class="col-md-3">
{% if profile %}
{% include "card.html" %}
{% else %}
{% endif %}
</div>
{% endfor %}
</div>
{% endfor %}
Captures part of template to variable that may then be displayed many more times.
There is also trimmed flavour `
` that trims captured template part before assinging it to variable.
Filter that formats date according to format defines in
MISAGO_COMPACT_DATE_FORMAT_DAY_MONTH
setting if date is in current year, or MISAGO_COMPACT_DATE_FORMAT_DAY_MONTH_YEAR
if not. Defaults to "7 may" for same year dates and "may '13" for past years dates.Takes form field as its first argument and renders field complete with label, help and errors. Accept two extra arguments: label class and field class, allowing you to control size of horizontal forms:
{% load misago_forms %}
{% form_row form.somefield %}
{% form_row form.otherfield 'col-md-3' 'col-md-9' %}
Takes form field as its only argument and renders it's input.
Turns value into json string. Perfoms additional escaping on
<
signs so </script>
are not interpreted as HTML resulting in XSS.Shorthand for simple if clauses:
{{ "fade in"|iftrue:thread.is_closed }}
will render fade in
in template if thread.is_closed
evaluates to True
.Opposite to
iftrue
. Outputs value if test evaluates to False
.Last modified 5yr ago