Using ‘Value Expression’ in OpenBots Documents.
What is Liquid templating language?
Basic Syntax of Liquid
Step-by-Step Guide to Creating Expressions
1. Combining Fields
– `FirstName = “John”`
– `LastName = “Doe”`
– `Gender = “Male”`
{% if Gender == “Male” %}
Mr. {{ FirstName }} {{ LastName }}
{% elsif Gender == “Female” %}
Ms. {{ FirstName }} {{ LastName }}
{% else %}
{{ FirstName }} {{ LastName }}
{% endif %}
2. Using Filters
{% if Gender == “Male” %}
MR. {{ FirstName | upcase }}
{{ LastName | upcase }}
{% elsif Gender == “Female” %}
MS. {{ FirstName | upcase
}} {{ LastName | upcase }}
{% else %}
{{ FirstName | upcase }}
{{ LastName | upcase }}
{% endif %}
3. Conditional Logic
{% if Age > 18 %}
Adult
{% else %}
Minor
{% endif %}
4. Iterating Over Collections
{% for item in items %}
{{ item }}
{% endfor %}
Practical Examples
– `FirstName = “Jane”`
– `LastName = “Smith”`
– `Street = “123 Main St”`
– `City = “Anytown”`
– `State = “CA”`
– `ZipCode = “12345”`
{{ FirstName }} {{ LastName }}
{{ Street }}
{{ City }}, {{ State }} {{ ZipCode }}
Jane Smith
123 Main St
Anytown, CA 12345
Example 2: Conditional Output Based on Document Type
{% if DocumentType == “Invoice” %}
Invoice Number: {{ InvoiceNumber }}
Date: {{ Date }}
Total: ${{ Total }}
{% elsif DocumentType == “Receipt” %}
Receipt Number: {{ ReceiptNumber }}
Date: {{ Date }}
Amount Paid: ${{ AmountPaid }}
{% endif %}
Tips for New Users
Category | Function Name | Description | Sample Usage |
---|---|---|---|
Math | abs | Returns the absolute value of a number. | {{ abs(-5) }} → 5 |
Math | ceil | Rounds a number up to the nearest integer. | {{ ceil(4.3) }} → 5 |
Math | floor | Rounds a number down to the nearest integer. | {{ floor(4.8) }} → 4 |
Math | round | Rounds a number to the nearest integer or specified precision. | {{ round(4.56, 1) }} → 4.6 |
Math | max | Returns the maximum value from a list of numbers. | {{ max(1, 2, 3) }} → 3 |
Math | min | Returns the minimum value from a list of numbers. | {{ min(1, 2, 3) }} → 1 |
String | lower | Converts a string to lowercase. | {{ lower("HELLO") }} → "hello" |
String | upper | Converts a string to uppercase. | {{ upper("hello") }} → "HELLO" |
String | replace | Replaces all occurrences of a substring with another string. | {{ replace("Hello world", "world", "Scriban") }} → "Hello Scriban" |
String | split | Splits a string into an array based on a delimiter. | {{ split("a,b,c", ",") }} → ["a", "b", "c"] |
String | substring | Extracts a substring from a string. | {{ substring("hello", 1, 3) }} → "ell" |
Array | size | Returns the number of elements in an array. | {{ size([1, 2, 3]) }} → 3 |
Array | reverse | Reverses the order of elements in an array. | {{ reverse([1, 2, 3]) }} → [3, 2, 1] |
Array | sort | Sorts an array in ascending order. | {{ sort([3, 1, 2]) }} → [1, 2, 3] |
Array | first | Returns the first element of an array. | {{ first([1, 2, 3]) }} → 1 |
Array | last | Returns the last element of an array. | {{ last([1, 2, 3]) }} → 3 |
Date | date.now | Returns the current date and time. | {{ date.now }} → "2024-08-13T12:00:00Z" |
Date | date.format | Formats a date according to a specified format. | {{ date.format(date.now, "%Y-%m-%d") }} → "2024-08-13" |
Date | date.add_days | Adds a number of days to a date. | {{ date.add_days(date.now, 5) }} → "2024-08-18" |
Date | date.parse | Parses a string into a date using a specified format. | {{ date.parse("2024-08-13", "%Y-%m-%d") }} → date object |
Control Flow | if | Executes a block of code if a condition is true. | {% if condition %} ... {% endif %} |
Control Flow | for | Iterates over each item in a collection or array. | {% for item in collection %} ... {% endfor %} |
Control Flow | while | Repeats a block of code while a condition is true. | {% while condition %} ... {% endwhile %} |
Utility | typeof | Returns the type of a value. | {{ typeof(123) }} → "number" |
Utility | Outputs a value to the console or output. | {{ print("Hello World") }} → "Hello World" |