Template Logic

General

LoanPro uses the Blitz template engine for custom forms. Blitz allows you to use logic in your custom forms to include or exclude sections of the form based on loan or customer data. For example, you could include an extra line in a bill if the customer was past due, or omit the line if the customer was current on the loan. For more information on what’s available in Blitz see the documentation.

Conditional Statements

The basic syntax for this functionality is fairly simple. First, it is necessary to enclose all logic statements in double curly braces {{}}. Second, any variables used should have a $ prepended directly to them.

Example:

{{ IF $setup-payment < 100 }}

In the above example, the payment variable appears with a $ directly in front of it. You will also notice that double brackets [[]] aren’t necessary when you use logic in your form. Now lets look at a complete IF statement example.

Example:

{{ IF $setup-payment > 100 }}

The payment amount is greater than $100.00

{{ END }}

The above statement will check to see if the payment amount is greater than 100. If it is, the statement “The payment amount is greater than $100.00” will appear in the form.

You can also use ELSE statements in the form. These will display one thing if your condition is met and another if it’s not.

Example:

{{ IF $setup-payment > 100 }}

The payment amount is greater than $100.00

{{ ELSE }}

The payment amount is less than $100.00

{{ END }}

In the example above, if the payment amount is greater than 100, the line “The payment amount is greater than $100.00” will be displayed in the form, otherwise the line “The payment amount is less than $100.00” will be displayed.

It is important to note that logic keywords like IF, ELSE, and END are not case sensitive.

Conditional statements work a little differently with array-style variables. In the example above, we used $setup-payment directly in the IF statement. With array-style variables, you must first use a loop and then you can create the IF statement inside the loop.

For example, if you want to use a custom field value in an IF statement, the custom field will appear on the form like this:

[[v(‘collateral-custom-fields.3.value’)]]

The .3 references a single collateral custom field, in this case, with the ID of 3. Value specifies that you want the value of this custom field. Unfortunately, you can’t create an IF statement as shown above.

{{ IF $collateral-custom-fields.3.value }} will not work. Instead, you will need to use a loop of collateral custom fields and then create the IF statement as follows:

{{ BEGIN collateral-custom-fields }}

{{ IF $value == ‘1’ }}

Value if true

{{ END }}

{{ END }}

Note that even if the value in the comparison is a number it will actually be saved as a string.

Loops

The syntax for loops is pretty simple. Start a loop using the word BEGIN along with an array-style variable name. End the loop using the word END. Both the opening and closing of a loop must be surrounded by double curly braces {{}}.

Example:

{{ BEGIN scheduled-payments }}

This is a payment.

{{ END }}

The above example would output the line “This is a payment.” for each of the scheduled payments on the loan.

You can have the loop output the properties of the array-style variable. The properties should be prepended with a $ and should be surrounded by double curly braces.

Example:

{{ BEGIN scheduled-payments }}

{{ $date }}

{{ END }}

The above example would output the date of each payment. Note that the spacing will matter. In the above example, each date will be on it’s own line. You can also use IF statements inside a loop.

Example:

{{ BEGIN scheduled-payments }}

{{ IF $amount > 100 }}

{{ $date }}

{{ END }}

{{ END }}

In the above example, you will display the dates for each payment that is for an amount that’s greater than $100.00. Finally, there are some built-in variables for use with loops that can help with you get the output you want. These variables are:

  • $_last – This equals true on the last iteration of the loop and false for other iterations.
  • $_total – This is the total number of iterations in the loop.
  • $_num – This is the iteration number. Arrays start with 0, but this variable will start at 1.
  • $_even – This is true for even iterations and false for odd iterations. Since arrays start at 0, this will be true in the first, third, fifth, etc. iterations.
  • $_odd – Works like $_even, but for the odd iterations.

Example:

{{ BEGIN scheduled-payments }}

{{ IF $_even }}

{{ $date }}

{{ END }}

{{ END }}

The above example will output the dates for every other payment in the array starting with the first one.

Additional Examples:

Example #2

Loan Portfolios: [[BEGIN portfolio]] [[title]][[if($_last,”,’,’)]] [[END]]

In this example we are only displaying a simple list of portfolios associated to the loan, but it also shows the use of an IF statement along with the special variable of $_last to determine if we need to show the comma in the current iteration. If it is the last iteration of the array then we don’t want to display the comma character.

Special note on IF statements: There are other predefined special loop variables: $_first, $_total, $_num, $_even, $_odd. $_last is a special variable, equal to 1 when the loop is on its last iteration and 0 otherwise.  $_total is the number of iterations in an array variable.  $_num is a current iteration number starting with 1.  $_even and $_odd are 1 or 0 depending on if the current iteration value is even or odd.

With the IF statement we get the following result:
Loan Portfolios: Test Portfolio, Another Portfolio, Secondary Portfolio

Without the IF statement (ie. [[BEGIN portfolio]] [[title]], [[END]]) then our results would look like this:
Loan Portfolios: Test Portfolio, Another Portfolio, Secondary Portfolio,

Example #3

Loan Payment Schedule:
<table><tbody>
<tr>
<th>Period</th>
<th>Payment Amount</th>
<th>Payment Date</th>
<th>Principal Remaining</th>
</tr>
<!–[[BEGIN scheduled-payments]]–>
<tr>
<td>[[period]]</td>
<td>$[[formatNumber([[amount]])]]</td>
<td>[[formatDateTime(‘[[date]]’)]]</td>
<td>$[[formatNumber([[principal-balance]])]]</td>
</tr>
<!–[[END]]–>
</tbody></table>

This example will iterate the scheduled payments on the loan from the loan transactions report, and will display a list of payment due dates and amounts. The example above would output something similar to the following formatted inside of a table using HTML:

Scheduled Payments:
Period Payment Amount Payment Date Principal Remaining
1 $439.58 10/01/2015 $4,602.09
2 $439.58 11/01/2015 $4,200.86
3 $439.58 12/01/2015 $3,796.29
4 $439.58 01/01/2016 $3,388.35
5 $439.58 02/01/2016 $2,977.01
6 $439.58 03/01/2016 $2,562.24
7 $439.58 04/01/2016 $2,144.01
8 $439.58 05/01/2016 $1,722.30
9 $439.58 06/01/2016 $1,297.07
10 $439.58 07/01/2016 $868.30
11 $439.58 08/01/2016 $435.96
12 $439.58 09/01/2016 $0.00

Note: When using recursive loops inside of HTML tables, the [[BEGIN]] and [[END]] statements must be encapsulated in HTML comment tags. See above.

Related Articles

Leave A Comment?