# 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 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]] {{ IF$_last }} [[title]]{{ ELSE }} [[title]],{{ END }}[[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: Example #3 This example will create a loan payment schedule using the HTML source code of a form, to get the the HTML editor while inside of the form editor select from the form tool options. Loan Payment Schedule: <p>Loan Payment Schedule:</p><tbody><tr><th style="width: 100px; text-align: left;">Period</th><th style="width: 150px; text-align: left;">Payment Amount</th><th style="width: 150px; text-align: left;">Payment Date</th><th style="width: 200px; text-align: left;">Principal Remaining</th></tr><tr><td style="width: 100px;"><p style="text-align: left;">[[BEGIN scheduled-payments]]</p><p>[[_num]]</p><p>[[END]]</p></td><td style="width: 150px;"><p style="text-align: left;">[[BEGIN scheduled-payments]]</p><p>$[[$amount]]</p><p>[[END]]</p></td><td style="width: 150px;"><p style="text-align: left;">[[BEGIN scheduled-payments]]</p><p>[[date]]</p><p>[[END]]</p></td><td style="width: 200px;"><p style="text-align: left;">[[BEGIN scheduled-payments]]</p><p>[[\$principal-balance]]</p><p>[[END]]</p></td></tr></tbody></table>

When entered in the HTML, 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: