Template Context

In addition to the standard Jinja2 filters, the following additional elements are available in the template context.

Name

Description

Example

checksum

The fingerprint value for the document. Every document template has a unique fingerprint which is calculated from its definition. Including the fingerprint in a document can provide assurance that a validated version of the document template has been used to generate a particular document.

Checksum : {{ checksum }}

convert_html

A filter function which attempts to turn HTML content into equivalent Word Document formats for display.

Only available in Word Document Templates

{{ field.PreText|convert_html }}

GENERATED_AT

A python date/time object in UTC timezone representing the start date/time of the document generation task.

See Python Date Formats.

Created at: {{ GENERATED_AT | timezone(USER_TIMEZONE_NAME) | format_datetime('%Y-%m-%d') }}

IS_TEST

A boolean representing whether the document template is being run in test mode from the document template editor.

{% if IS_TEST %}RUNNING IN TEST MODE{% endif %}

len

The python len() function. Returns the length of a list or string

{% if len(fields) > 10 %}...{% endif %}

now()

now() function returns a python DateTime object representing the current server time with UTC timezone.

See Python Date Formats.

Time is now: {{ now() | format_datetime(('%d %b %Y %H:%M:%S') }}

settings

A python dictionary of settings provided by the user (these may just be the defaults for the template)

{{ settings.get("form_order","Ordinal") }}

template_name

The name of the Document Template being executed.

Template: {{ template_name }}

timezone

Converts a datetime value into the timezone provided.

See List of Time Zones.

User Time : {{ now()|timezone(USER_TIMEZONE_NAME)|format_datetime('%Y-%m-%d') }}
Time in NY : {{ now()|timezone("America/New_York")|format_datetime('%Y-%m-%d') }}

user

The User object for the user running the report.

Run by {{ user.username }}

USER_TIMEZONE_NAME

The name of the timezone of the user running the document template. e.g. Europe/London

See List of Time Zones.

Timezone : {{ USER_TIMEZONE_NAME }}

wiki_page(name)

A function which returns a Wiki page from the Drafts Project Wiki, formatted using the convert_html filter above. This is useful for injecting content maintained in the Wiki into documents.

Only available in Word Document Templates

{{ wiki_page("Design Notes") }}

Draft Home Templates

The following additional context variables are available in templates with a scope of Draft Home:

Name

Description

Example

draft

A draft reference. The root object from which Draft properties and sub objects such as lists of Forms or Folders can be accessed.

The draft variable is only available when the document template scope is of type Draft Home

Draft {{ draft.DraftName}} in Project {{ draft.Project.ProjectName }}

Project Home Templates

The following additional context variables are available in templates with a scope of Project Home:

Name

Description

Example

project

A project reference. The root object from which Project properties and sub objects such as lists of Drafts or Tickets can be accessed.

The project variable is only available when the document template scope is of type Project Home or Project Tickets

{{ project.ProjectName }}

Project Ticket Templates

The following additional context variables are available in templates with a scope of Project Tickets:

Important

When running document templates in testing from the document template editor the filter_assignments are set to "All", filter_labels are set to empty list, search_text is empty string, filtered_ids is an empty list and ticket_page is set to "All".

Name

Description

Example

project

A project reference. The root object from which Project properties and sub objects such as lists of Drafts or Tickets can be accessed.

The project variable is only available when the document template scope is of type Project Home or Project Tickets

{{ project.ProjectName }}

filter_assignments

The assignment filter selected in the ticket view that the document was generated from. Can be one of "All", "Unassigned" or "Assigned to me". Defaults to "All".

Assignments Filter : {{ filter_assignments }} {# All, Unassigned, Assigned to me #}

filter_labels

A list of labels which the ticket view is being filtered by. Empty list if view not being filtered by label.

{{ ", ".join(filter_labels) or 'None' }}

filtered_ids

Database ids of the records which are viewable in the ticket view that the document was generated from. This allows the document template author to report on just the tickets that the user has the view filtered to.

{% for ticket in project.ticket_set.filter(id__in=filtered_ids).order_by('iid') %}

search_text

The contents of the "search" box on the ticket view that the document was generated from

Active Search: {{ search_text or 'None' }}

ticket_page

The sub-page of the ticket view that the document was generated from. Can be "open", "closed" or "all"

Ticket Page: {{ ticket_page.title() }}