Skip to content

Commit f1f12bb

Browse files
Florian KrönertFlorian Krönert
authored andcommitted
2 parents 259ac79 + eace0a2 commit f1f12bb

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Using XTL provides the following benefits:
8080

8181
## Types
8282
Native Types:
83-
- String Constants (Alpha numeric text inside quotes)
83+
- String Constants (Alpha numeric text inside double quotes or single quotes)
8484
- Integers (Digit expression)
8585
- Doubles (Digits are separated by '.', a 'd' is appended to separate from decimals. E.g: 1.4d)
8686
- Decimals (Digits are separated by '.', a 'm' is appended to separate from doubles. E.g: 1.4m)
@@ -343,7 +343,7 @@ Above example could return something like 'Baggins, Frodo'.
343343
Takes the substring of your input starting from a given index. Length of substring can be passed optionally as well.
344344

345345
Example:
346-
```
346+
``` JavaScript
347347
Substring(Value("firstname"), 1, 2 )
348348
```
349349
Above example returns 'ro' when input is 'Frodo'.
@@ -445,6 +445,68 @@ Format( Value("index"), { format: "{0:00000}" } ) // Will print 00001 for index
445445

446446
Refer to the .NET style for date formatting.
447447

448+
### Snippet
449+
> Snippets are available in XTL >= v3.7
450+
451+
Snippets are an easy way for storing texts globally, so that they can be referred to from anywhere in the system.
452+
They are stored in the XTL Snippet entity. You can use them as simple storage for a single (long) XTL expression, or even pass a complete text with embedded XTL expressions in the usual fashion (${{expression}}) inside it.
453+
When only saving a XTL expression, be sure to set "Contains Plain text" to "No", so that XTL will automatically wrap your expression in ${{ ... }} brackets.
454+
When saving a complete text with embedded XTL expressions, set "Contains Plain Text" to "Yes", so that XTL will do no automatic wrapping.
455+
456+
You can use the unique name inside the XTL snippet record for referring to it, or you can use the normal name and refer to it using its name and a custom fetchXml filter.
457+
The second parameter is especially useful, as you can create custom fields on the snippet entity, for example a language field, and use the filter for fetching the correct language dynamically.
458+
459+
For the following examples, lets define some XTL snippets that we can imagine to be existent in our organization:
460+
461+
Snippet 1 (used for fetching the owner's name on any entity)
462+
- oss_uniquename: "OwnerName"
463+
- oss_containsplaintext: false
464+
- oss_xtlexpression: Value("ownerid.name")
465+
> Remember: We must not wrap the expression in the usual ${{...}} brackets in this case, this will be done automatically, when "Contains Plain Text" is false
466+
467+
Snippet 2 (used for generating a contact's salutation)
468+
- oss_uniquename: "Salutation_EN"
469+
- oss_containsplaintext: true
470+
- oss_xtlexpression: Dear ${{If(IsEqual(Value("gendercode"), 1), "Mr.", "Ms.")}} ${{Value("lastname")}}
471+
472+
Snippet 3 (used for generating a contact's salutation)
473+
- oss_name: "salutation"
474+
- oss_containsplaintext: true
475+
- new_customlanguage: "EN"
476+
- oss_xtlexpression: Dear ${{If(IsEqual(Value("gendercode"), 1), "Mr.", "Ms.")}} ${{Value("lastname")}}
477+
478+
#### Example - Refer to Snippet using unique name
479+
Refers to Snippet 1, which will be matched by the following expression:
480+
481+
```JS
482+
Snippet("OwnerName")
483+
```
484+
485+
#### Example - Refer to snippet with dynamic name
486+
Refers to Snippet 2, which will be matched by the following expression:
487+
488+
``` JavaScript
489+
Snippet(Concat("Salutation_", Value("new_languageisocode"))
490+
```
491+
492+
When running this on a contact with "new_languageisocode" equal to "EN", this will resolve to snippet name "Salutation_EN" and snippet 2 will thus be found.
493+
494+
#### Example - Refer to snippet with simple filter
495+
Refers to Snippet 3, which will be matched by the following expression:
496+
497+
``` JavaScript
498+
Snippet("salutation", { filter: '<filter><condition attribute="new_customlanguage" operator="eq" value="EN" /></filter>' })
499+
```
500+
501+
#### Example - Refer to snippet with dynamic filter
502+
Refers to Snippet 3, which will be matched by the following expression:
503+
504+
``` JavaScript
505+
Snippet("salutation", { filter: '<filter><condition attribute="new_customlanguage" operator="eq" value="${{Value("new_languageisocode")}}" /></filter>' })
506+
```
507+
508+
Before using the custom filter, all XTL tokens will be processed, so for a contact with "new_languageisocode" equal to "EN", the expression inside the filter value would be exchanged for "EN" and the correct snippet found and applied.
509+
448510
## Sample
449511
Consider the following e-mail template content:
450512
```

0 commit comments

Comments
 (0)