Loading...

The basics of Expressions

An expression is essentially a JavaScript syntax enclosed in {{ and }}. The expression is any valid set of variables, operators, and expressions that evaluates to a single value. The value may be a number, a string, an array or a logical value.

The following is a Label component that supports expression and it’s used to display a variable invoice_number

A property that supports Expression
A property that supports Expression

Examples

An expression in JavaScript is a syntax enclosed in double curly braces {{ and }}. It allows the use of JavaScript code within the expression. Here are some examples of using expressions:

Example 1 - Addition of 2 numeric values

{{ 1+1 }}

Result

2


Example 2 - Display "hello". You can use either {{ and }} or alternatively {% and %}. They are interchangable.

{% "hello" %}

Result

Hello


Example 3 - Display the JSON field "title"

{{ data.title }}

Example 4 - Conditional (ternary) operator

{{ data.status == 2 ? "Pending" : "Unknown" }}

Supported libraries

(i) Standard JavaScript libraries – JavaScript standard built-in functions and objects such as MathStringArray or any standard Javascript methods.

(ii) External libraries – We support Numeral.js and Moment.js out of the box

(iii) CraftMyPDF’s built-in functions – functions for formatting, number and string. You may find them in the designer Docs: Expressions or in the support page

Docs: Expressions
Docs: Expressions