Wagtail supports Jinja2 templating for all front end features. More information on each of the template tags below can be found in the Writing templates documentation.
Django needs to be configured to support Jinja2 templates. As the Wagtail admin is written using standard Django templates, Django has to be configured to use both templating engines. Add the Jinja2 template backend configuration to the TEMPLATES
setting for your app as shown here:
TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", # ... the rest of the existing Django template configuration ... }, { 'BACKEND': 'django.template.backends.jinja2.Jinja2', 'APP_DIRS': True, 'OPTIONS': { 'extensions': [ 'wagtail.jinja2tags.core', 'wagtail.admin.jinja2tags.userbar', 'wagtail.images.jinja2tags.images', ], }, } ]
Jinja templates must be placed in a jinja2/
directory in your app. For example, the standard template location for an EventPage
model in an events
app would be events/jinja2/events/event_page.html
.
By default, the Jinja environment does not have any Django functions or filters. The Django documentation has more information on django.template.backends.jinja2.Jinja2
(configuring Jinja for Django).
self
in templatesIn Django templates, self
can be used to refer to the current page, stream block, or field panel. In Jinja, self
is reserved for internal use. When writing Jinja templates, use page
to refer to pages, value
for stream blocks, and field_panel
for field panels.
© 2014-present Torchbox Ltd and individual contributors.
All rights are reserved.
Licensed under the BSD License.
https://docs.wagtail.org/en/stable/reference/jinja2.html