Skip to content

Variable Interpolation in Text

andydhancock edited this page Nov 16, 2023 · 1 revision

Variable Interpolation in Text

LegaleseScript allows for the inclusion of variables directly within the text of a contract through a process called variable interpolation. This feature enables the dynamic insertion of variable values into the contract text, making the template more flexible and easier to read.

Syntax for Variable Interpolation

To interpolate a variable into the text, use the curly braces {} syntax with the variable name inside.

Example of Variable Interpolation

Text contractIntroduction = "This Agreement is made between {employer} and {employee} on {effectiveDate}.";

When the contract is processed, {employer}, {employee}, and {effectiveDate} will be replaced with their respective variable values.

Defining Variables

Before you can interpolate variables, they must be defined in the scope of the contract.

Defining and Interpolating Variables

section EmploymentAgreement {
    Party employer = "Acme Corporation";
    Party employee = "John Doe";
    Date effectiveDate = Date("2023-01-01");

    Text contractIntroduction = "This Agreement is made between {employer} and {employee} on {effectiveDate}.";
    
    // Logic and obligations go here
}

In this example, the contractIntroduction text will render as "This Agreement is made between Acme Corporation and John Doe on 01 January 2023." once processed.

Dynamic Replacement

During the rendering or compilation process, LegaleseScript will dynamically replace the placeholders with actual variable values.

Process of Dynamic Replacement

// When the contract is compiled or rendered, the placeholders are replaced:
render(contractIntroduction);
// Output: This Agreement is made between Acme Corporation and John Doe on 01 January 2023.

Conclusion

Variable interpolation is a powerful feature of LegaleseScript that simplifies the creation of dynamic and reusable contract templates. By embedding variables directly within the contract text, authors can create contracts that are both flexible and maintain the formal structure required for legal documents.

Clone this wiki locally