Markup expressions and operators
For context on what markup can be used for, see Understand markup.
In every field that supports markup, values between double curly braces ({{...}}
) are treated as markup. A number of expressions and operators can be used to modify data before it is stored.
Form data keys
Within markup, form data can be referenced by its key. For example, if you have form data keys name
and city
, you can reference them as follows:
Hello {{name}}! Your city is {{city}}.
In a conversation where the key name
has been set to the value "User" and the key city
has the value "New York", the above will evaluate to and display as this:
Hello User! Your city is New York.
This works with form data created by your flow and also with reserved form data created automatically by Mavenoid. For example, you can reference the reserved key $language-iso
as follows:
Hello! We will show you resources in language "{{$language-iso}}."
If the conversation is occurring in English, the above will evaluate to and display as:
Hello! We will show you resources in language "en."
Conditionals
In most cases, referencing a key which is not set will result in an error. To reference a key which may or may not be set, you can prepend ?
to its name.
For example, if you have a form data key order-status
but may or may not have a form data key order-message
, you can safely reference these values as follows:
Order status:
{{order-status}}
{{?order-message}}
If order-status
has the value "Complete" and order-message
has the value "Completed on Tuesday", the above will evaluate to and display as:
Order status:
Complete
Completed on Tuesday
Whereas if order-status
has the value "Pending" and order-message
is not set, the above will evaluate to and display as:
Order status:
Pending
Concatenation
There is not a concatenation operator as such, but you can simply reference multiple form data keys in sequence. For example, if you have form data keys first_name
and last_name
, you can reference them together as follows:
Full name: {{first_name}} {{last_name}}
If the key first_name
has a value of "Example" and last_name
has a value of "User", the above will evaluate to and display as:
Full name: Example User
Math
You can use +
, -
, *
, and /
as mathematical operators to add, subtract, multiply or divide any numbers or numeric form data. Parentheses are also supported for order of operations.
For example, if you have form data keys length
with value "7", width
with value "4", and balcony_area
with value "21", you can write markup as follows:
Room area: {{length * width}} square feet
Balcony area: {{balcony_area}} square feet
Total area: {{(length * width) + balcony_area}} square feet
Total area for two rooms: {{((length * width) + balcony_area) * 2}} square feet
The above will evaluate to and display as this:
Room area: 28 square feet
Balcony area: 21 square feet
Total area: 49 square feet
Total area for two rooms: 98 square feet
Path expressions
You can use JSON path expressions to reference specific fields or values within arrays, maps, or JSON objects.
Member names or numbers
You can access specific members within an object or array by adding ["name"]
to the relevant key, where "name"
is the name of the member you are referencing.
For example, every conversation has a reserved form data key of $session
with a value something like this:
{"id": "2C3874A", "url": "https://app.mavenoid.com/org/ORG-NAME/product/123456/s/2C3874A"}
To reference the "url"
value within, you can write markup like this:
You can resume your session by visiting {{$session["url"]}} at any time.
The above would evaluate to and display as something like this:
You can resume your session by visiting https://app.mavenoid.com/org/ORG-NAME/product/123456/s/2C3874A at any time.
You can also use this to reference numbered elements in an array. For example, if you have a form data key screenshots
that was used for an (image/video upload form field](reference-form-field-types#imagevideo-upload), the value of that form data might look something like this:
[
{
"fileUrl":"https://mavenoidfiles.com/12345678abcdefgh12345678",
"fileType":"image/png",
"fileName":"screenshot1.png"
},
{
"fileUrl":"https://mavenoidfiles.com/ijklmnop12345678ijklmnop",
"fileType":"image/png",
"fileName":"screenshot2.png"
}
]
If you wanted to retrieve the "fileUrl" for the zeroth uploaded file, no matter how many were uploaded, you can write markup like this:
You can see your uploaded file at {{screenshots["0"]["fileUrl"]}}
With the value shown above, this would evaluate to and display as:
You can see your uploaded file at https://mavenoidfiles.com/12345678abcdefgh12345678
Member wildcards
You can access all members within an object or array by using *
as the member name. Values will be grouped into an array.
For example, if you have a form data key screenshots
that was used for an (image/video upload form field](reference-form-field-types#imagevideo-upload), the value of that form data might look something like this:
[
{
"fileUrl":"https://mavenoidfiles.com/12345678abcdefgh12345678",
"fileType":"image/png",
"fileName":"screenshot1.png"
},
{
"fileUrl":"https://mavenoidfiles.com/ijklmnop12345678ijklmnop",
"fileType":"image/png",
"fileName":"screenshot2.png"
}
]
To access all "fileName" values no matter how many there are, you can write markup like the following:
You have uploaded the following files: {{screenshots[*]["fileName"]}}
With the value shown above, this would evaluate to and display as:
You have uploaded the following files: ["screenshot1.png","screenshot2.png"]
Iterators
You can iterate over members in an array using the following syntax:
{{#each $<IDENTIFIER> in <EXPRESSION>}}
<BODY-EXPRESSION>
{{#end}}`
For example, if you had the form data key products
populated with the following JSON value:
[
{
"name": "Product 1",
"url": "https://example.com/product1.html"
},
{
"name": "Product 2",
"url": "https://example.com/product2.html"
},
]
You could turn it into a series of markdown links by writing markup like the following:
{{#each $product in products}}
[{{$product["name"]}}]($product["url"])
{{#end}}
Given the above value, this would evaluate to the following:
[Product 1](https://www.my-store.com/product1.html),[Product 2](https://www.my-store.com/product2.html)
Which would render as two markdown links.
For an example of using iterators to dynamically populate a choice list, see Dynamically populate a choice list - Iterator.