Template Context
In addition to the standard Jinja2 filters, the following additional elements are available in the template context.
These values are available whatever the Template's scope. Each scope then adds the objects that scope reports on — the Draft, the Project, or the rows of a listing:
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.
|
{{ field.PreText|convert_html }}
|
GENERATED_AT |
A python date/time object in UTC timezone representing the start date/time of the document generation task.
|
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 %}
|
project_role_for_user(user) |
project_role_for_user(user) takes a User object and returns the User Project Role that the user has in this Project. |
Hello {{ user.username }} your role in the project is {{ project_role_for_user(user).name }}
|
user_by_id(id) |
user_by_id(id) takes the value of a User Custom Property and returns the
User it names, so you can show the person's name and email address rather
than the stored number.
|
{% set owner = user_by_id(form.properties['form owner'].value) %}
{% if owner %}Owner: {{ owner.username }} ({{ owner.email }}){% endif %}
|
now() |
now() function returns a python DateTime object representing the current server time with UTC timezone.
|
Time is now: {{ now() | format_datetime(('%d %b %Y %H:%M:%S') }}
|
settings |
A python dictionary of the values the user chose in the generation dialog, keyed by the Setting's
Name. Every Setting defined on the Template is present, holding its Default when the user did not
change it.
|
{{ settings.get("form_order") }}
|
template_name |
The name of the Document Template being executed. |
Template: {{ template_name }}
|
timezone |
Converts a datetime value into the timezone provided.
|
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
|
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.
|
{{ wiki_page("Design Notes") }}
|