Custom templates

Custom templates

Custom templates in agileBase are typically used to create output that needs to be printed or emailed, for example form letters and especially anything that needs to be branded. They can be used for some quite complex and large documents, for example one customer uses them to create branded multi-page reports that are sold to customers, complete with custom fonts, layouts, images and colours.

We’ll just cover the basics here, if you have more advanced needs please get in touch and we’ll be happy to help you get going.

The concepts

Each template is a HTML file that includes variables output from agileBase. The variables come from the current view and table selected by the user, or alternatively from specific sources defined in the template. So for example a user could select a contact, then press ‘print’ and choose from a selection of documents to merge data into.

Note that calculations from a view as well as standard fields can be included in templates.

One or more templates can be uploaded per view. In the administration interface, select a view, then press the print button in the toolbar. The two default print options will appear, i.e. the option to print the currently selected record or a list of all filtered records in the view.

Ignore these and press the ‘manage’ button at the top right. This will let you upload one or more templates into the view.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Letter example</title>
</head>

<body>
<br />
<br />
<br />
<br />
<br />
<br />
$salutation $surname <br /> 
$mailing_house_name <br />
$mailing_no_and_street<br /> 
$mailing_town <br /> 
$mailing_city<br />
$mailing_county<br />
$mailing_postcode<br />
<br />

Our Ref: $lead_number<br />
<br />
$viewTools.getDatestampString()<br />
 
<p>Dear $salutation $surname</p>

<p>APPOINTMENT: $sales_appointment</p>

<p>I write to thank you for your valued enquiry. etc. etc.</p> 
<p> Yours sincerely</p>
<br />
<br />
<p>Oliver Kohll</p>
<p>Sales and Marketing Co-odrinator</p>
</body>
</html>

Example 1: a letter

This template will merge data from the current record in. Note that field names have dollar signs below them. They match the field names in agileBase except

  1. they are all lower case
  2. spaces are replaced by underscores (_)
  3. all characters that are neither letters nor numbers are removed

Example 2

Similar to example 1, this template prints the same letter, but one copy for each row in the current view.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Letter example</title>
</head>
<body>
#set($rows = $view.getReportDataRows())
#foreach($row in $rows)
  #set($salutation = $row.getValue("salutation"))
  #set($surname = $row.getValue("surname"))
  #set($mailing_house_name = $row.getValue("mailing house name"))
  #set($mailing_no_and_street = $row.getValue("mailing no and street"))
  #set($mailing_city = $row.getValue("mailing city"))
  #set($mailing_county = $row.getValue("mailing county"))
  #set($mailing_postcode = $row.getValue("mailing postcode"))
  #set($lead_number = $row.getValue("lead number"))
  <br style="page-break-before: always;" />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  $salutation $surname <br /> 
  $mailing_house_name <br />
  $mailing_no_and_street<br /> 
  $mailing_town <br /> 
  $mailing_city<br />
  $mailing_county<br />
  $mailing_postcode<br />
  <br />
  Our Ref: $lead_number<br />
  <br />
  $viewTools.getDatestampString()<br />
 
  <p>Dear $salutation $surname</p>
  <p>APPOINTMENT: $sales_appointment</p>
  <p>I write to thank you for your valued enquiry. etc. etc.</p> 
  <p> Yours sincerely</p>
  <br />
  <br />
  <p>Oliver Kohll</p>
  <p>Sales and Marketing Co-odrinator</p>
#end ## End of foreach loop around rows
</body>
</html>

Advanced needs

A number of other capabilities exist within templates, powered by our extensive templating API, which uses the Apache Velocity language. Data from any agileBase view can be filtered and queried and a number of formatting tools are included, for example to turn numbers (1,200) into words (“one thousand, two hundred”). The full Java API can be used on any String objects.

For further information, please get in touch.

Last modified October 16, 2023: Update custom-templates.md (dc71df9)