About this article
This article explains what the StringJoin() function is and provide examples of how it can be used with the binding syntax in smart templates.
Prerequisites
|
What is the StringJoin() function?
StringJoin() is a commonly used function that joins multiple pieces of text together with a separator in between.
StringJoin() logic
Syntax | {{StringJoin(Separator, Value1, Value2, Value3...)}} |
Input | Separator and text |
Output | Joined text with the separator in between |
StringJoin() function examples
Example 1
Using the StringJoin() function to join two pieces of text with a dash in between.
Binding | {{StringJoin("-", "text1", "text2")}} |
Output | "text1-text2" |
|
Example 2
Using the StringJoin() function to join three pieces of text with a slash in between.
Binding | {{StringJoin("/", "text1", "text2", "text3")}} |
Output | "text1/text2/text3" |
Example 3
Using the StringJoin() function together with the "Separator" question originating from the response form where the user will be able to define the desired separator that should separate the address.
Binding | {{StringJoin(Form.Separator, Form.Street, Form.City, Form.Zipcode, Form.Country)}} | |
Input | Form.Separator = "-" | Form.Separator = "/" |
Output | "123 Washington Rd.-Lake Forest-60045-USA" | "123 Washington Rd./Lake Forest/60045/USA" |
Example 4
Using the StringJoin() function together with the "Zipcode" question originating from the response form, if the Zipcode question isn't filled by the user, the separator will be skipped.
Binding | {{StringJoin(" | ", Form.Street, Form.City, Form.Zipcode, Form.Country)}} | |
Input | Form.Zipcode = "" | Form.Zipcode = "60045" |
Output | "123 Washington Rd. | Lake Forest | USA" | "123 Washington Rd. | Lake Forest | 60045 | USA" |
Example 5
Using the StringJoin() function together with the FormatDateTime() function.
Binding | {{StringJoin(" | ", FormatDateTime(Form.Date, "dd/MM/yyyy", "en-US"), Form.Title, Form.Name)}} | |
Input |
Form.Date = "2023-3-17" Form.Title = "Report" Form.Name = "HR" |
Form.Date = "" Form.Title = "Report" Form.Name = "HR" |
Output | "17/03/2023 | Report | HR" | "Report | HR" |
|
Example 6
Using the StringJoin() function together with IfElse() to only insert the address if the "IncludeAddress" checkbox question originating from the response form is checked.
Binding | {{IfElse(Form.IncludeAddress, StringJoin(" | ", Form.Street, Form.City, Form.Zipcode, Form.Country), "")}} | |
Input | Form.IncludeAddress = "☑" | Form.IncludeAddress = "☐" |
Condition | True | False |
Output | "123 Washington Rd. | Lake Forest | 60045 | USA" | Empty content control |
Example 7
Using the IfElse() function in combination with StringJoin() to hide text (using a Group element) if both questions 1 and 2 are empty.
Binding | {{IfElse(Equals(StringJoin("", Form.Question1, Form.Question2), ""), VisibilityType.Hidden, VisibilityType.Visible)}} | |
Input |
Form.Question1 = "" Form.Question2 = "" |
Form.Question1 = "Hello world" Form.Question2 = "" |
Output | Hidden text | Visible text |
Example 8
Using a nested StringJoin() function together with IfElse() to show plain text ("E:", "P:" and "W:") combined with the value originating from the user profile.
Binding | {{StringJoin(" | ", StringJoin(" ", IfElse(Equals(UserProfile.Email, ""), "", "E:"), UserProfile.Email), StringJoin(" ", IfElse(Equals(UserProfile.Phone, ""), "", "P:"), UserProfile.Phone), StringJoin(" ", IfElse(Equals(UserProfile.Website, ""), "", "W:"), UserProfile.Website))}} | |
Input |
UserProfile.Email = "info@test.com" UserProfile.Phone = "" UserProfile.Website = "www.test.com" |
UserProfile.Email = "info@test.com" UserProfile.Phone = "+31401234567" UserProfile.Website = "www.test.com" |
Output | E: info@test.com | W: www.test.com |
E: info@test.com | P: +31401234567 | W: www.test.com |
Example 9
Using a nested StringJoin() function in combination with IfElse() to show plain text depending on the document language, combined with the value of the user profile field.
This is the same binding used in example 7, but with the plain text ("E:", "P:" and "W:") replaced by the Translate() function. The Translations data source looks like this:
Binding | {{StringJoin(" | ", StringJoin(" ", IfElse(Equals(UserProfile.Email, ""), "", Translate("EmailShort", DocumentLanguage)), UserProfile.Email), StringJoin(" ", IfElse(Equals(UserProfile.Phone, ""), "", Translate("PhoneShort", DocumentLanguage)), UserProfile.Phone), StringJoin(" ", IfElse(Equals(UserProfile.Website, ""), "", Translate("WebsiteShort", DocumentLanguage)), UserProfile.Website))}} | |
Input |
UserProfile.Email = "info@test.com" UserProfile.Phone = "+31401234567" UserProfile.Website = "www.test.com" DocumentLanguage = "en-US" |
UserProfile.Email = "info@test.com" UserProfile.Phone = "+31401234567" UserProfile.Website = "www.test.com" DocumentLanguage = "nl-NL" |
Output | E: info@test.com | P: +31401234567 | W: www.test.com |
E: info@test.com | T: +31401234567 | W: www.test.com |
Example 10
Using the StringJoin() function with separators will always display all the values on one line. To show each value on a separate line, you can use the escape sequence \n
to create a new line. However, \n
cannot be typed directly in Template Designer. Instead, specific steps must be followed in Word and PowerPoint.
In Word:
- Create a binding using StringJoin().
For example:{{StringJoin(" ", UserProfile.Email, UserProfile.Phone, UserProfile.Website)}}
- Open the properties of the content control from the Developer tab.
- In the Tag field, change
{{StringJoin(\" \",
to{{StringJoin(\"\n\",
. - The result looks like this:
|
In PowerPoint:
- Create a binding on a shape using StringJoin().
For example:{{StringJoin(" ", UserProfile.Email, UserProfile.Phone, UserProfile.Website)}}
- Right-click the Shape and select
Edit Alt Text
. - In the Alt Text task pane, change the part
{{StringJoin(\" \",
to{{StringJoin(\"\n\",
. - The result looks like this:
Binding (Tag in Word / Alt Text in PowerPoint) |
{"templafy":{"type":"text","binding":"{{StringJoin(\"\n\", UserProfile.Email, UserProfile.Phone, UserProfile.Website)}}"}} | |
Input |
UserProfile.Email = "info@test.com" UserProfile.Phone = "" UserProfile.Website = "www.test.com" |
UserProfile.Email = "info@test.com" UserProfile.Phone = "+31401234567" UserProfile.Website = "www.test.com" |
Output |
E: info@test.com W: www.test.com |
E: info@test.com T: +31401234567 W: www.test.com |
Related articles
Comments
Article is closed for comments.