Use Case: Multi-Branch Contract
Some documents need to change quite a lot depending on a single category, for example an employment contract that reads differently for full time, part time, and contractor hires. This example chains together several if / elsif / else blocks and nests additional conditions inside each one.
EMPLOYMENT CONTRACT
Employee: {{employee.name}}
{{employee.address}}
{{#if employee.type == "fulltime"}}
FULL TIME EMPLOYMENT AGREEMENT
Position: {{position.title}}
Salary: ${{salary.annual}} per year
{{#if salary.annual >= 100000}}
Executive Level Position: stock options available.
{{/if}}
{{#elsif employee.type == "parttime"}}
PART TIME EMPLOYMENT AGREEMENT
Hourly Rate: ${{salary.hourly}}/hour
Expected Hours: {{schedule.hoursPerWeek}} hours per week
{{#if schedule.hoursPerWeek >= 20}}
Eligible for partial benefits package.
{{#else}}
Not eligible for benefits.
{{/if}}
{{#elsif employee.type == "contractor"}}
CONTRACTOR AGREEMENT
Project: {{project.name}}
Rate: ${{contractor.rate}} per {{contractor.rateType}}
{{contractor.remote ? "Remote work approved" : "On site work required"}}
{{/if}}
{{#if employee.hasSecurityClearance}}
SECURITY CLEARANCE SECTION
Clearance Level: {{security.level}}
{{/if}}
A few things worth understanding about this pattern:
- Only one of the three employment types ever prints. Formaliq checks them in order (full time, then part time, then contractor) and stops at the first one that matches the form's answer.
- Conditions can be nested inside other conditions. The executive level note only appears inside the full time branch, and only when the salary also meets the threshold.
- A completely separate condition, like the security clearance section, can
sit alongside the employment type branch without interfering with it. It
uses the same
{{#if}}tag as everything else, wrapping a whole section works exactly the same way as wrapping a single paragraph. Conditions only need to avoid conflicting with others in their own if / elsif chain, not with every condition in the whole document.
This builds on the full example on the Conditional Logic page, adding a third branch and an extra layer of nesting.