Report Templates are required for reports that are scheduled with the ‘Delivery Format’ set to HTML. The template is an HTML document that contains markup tags which are parsed by the server and the generated output is sent via email.
The markup syntax is provided by the Django template language. Variable values can be identified by two curly braces {{ tag }}, while expressions are a single curly brace followed by a percentage sign {% do something %}.
For documentation on the capabilities for Django template, please refer to the project documentation page:
https://docs.djangoproject.com/en/1.11/ref/templates/language/#tags
The following variables are exposed to the Django template:
start_date | Start of the data sample in ISO format. |
end_date | End of the data sample in ISO format. |
tenant.name | The name of the tenant object. |
environment.name | The name of the environment. |
data | Raw data object. |
data_js | Data formatted to charts.js style for ease of use. |
aggregated_data | Raw data aggregated for ease of use. |
group_data | Raw business unit data. |
group_data_js | Business unit data formatted to chart.js format. |
group_aggregated_data | Business unit data in an aggregated format. |
Rendering the chart elements can be achieved by a small amount of JavaScript coding and the use of libraries, such as Chart.js. Variables that end with _js are intended to be used within an HTML script tag to create a JavaScript variable.
For example:
{% autoescape off %}
<script language="JavaScript">
var data_js = {{data_js}};
var group_data_js = {{group_data_js}};
</script>
{% endautoescape %}
With the use of the JavaScript library JQuery, it is possible to generate a report that retrieves data from external sources to be included within the report.