Template Context
The following elements are available in the template context. Every filter a template can use, with an example of each, is listed in Filters.
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 or Excel formats for display.
|
{{ field.PreText|convert_html }}
|
fail(message) |
Stops generation. No document is produced, and the generation fails showing message, so a
template can refuse to run when what it reports on is not in a state it should report on. A
test run from the Document Template editor shows the message the same way.
|
{% if conflicts %}
{{ fail("Scripter and Tester found to be the same for: " ~ conflicts|join(", ")) }}
{% endif %}
|
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 %}
|
compare_to_standard(object) |
compare_to_standard(object) compares an object with its Library Standard, as the Compare dialog
does, and returns the differences, Standard Rules and explanations. See
Comparing Objects.
|
{% set result = compare_to_standard(form) %}
{% if result %}{{ result.summary.differences.total }} differences{% endif %}
|
compare(first, second) |
compare(first, second) compares two objects of the same kind directly and returns every difference. See Comparing Objects. |
{% set result = compare(first_form, second_form) %}
{{ result.has_changes }}
|
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.
Place it on its own line, outside any |
{{ wiki_page("Design Notes") }}
|