Templates

The > operator allows capturing multiline text blocks using indentation.

How it works#

The content must have more left margin than the > and must be assigned to a variable or property.

> MESSAGE
  The lines
      respect the margin
  with precision

print MESSAGE
Automatic cleanup

The compiler automatically removes garbage characters that are outside the margin.

Interpolation#

Just like double quotes, templates allow interpolating values.

name = "Ana"
balance = 100
tax = 15

> JSON
 {
    "name": "$name",
    "total": ${balance - tax}
 }

print JSON
No direct escape sequences

Templates, by design, do not allow escape sequences.

> TEXT
 This \n is literal

print TEXT

However, if you really need an escape sequence, you can interpolate it:

LF = "\n"

> TEXT
 First line${LF}Second line

print TEXT

Conditional use#

Templates integrate with control flow:

name = "Ismael"
age = 23

type <- "Enter 0 for JSON or 1 for XML: "

if type == 0
    > TEMPLATE
     {
        "name": "$name"
        "age": $age
     }
elif type == 1
    > TEMPLATE
     <person>
        <name>$name</name>
        <age>$age</age>
     </person>

print TEMPLATE