Contact Us 1-800-596-4880

compose

compose(Array<String>, Array<String>): String

Uses a custom string interpolator to replace URL components with a encodeURIComponent result. You can call this function using the standard call, or a simplified version.

Parameters

Name Description

baseStringArray

A string array that contains the URL parts to interpolate using the strings in the interpolationStringArray parameter.

interpolationStringArray

A string array that contains the strings used to interpolate the baseStringArray.

Example

The following example uses the compose function to form an encoded URL, the first parameter is an array of two strings that are part of the URL and the second parameter is the urlPath variable that is used to interpolate the strings in the first parameter. Notice that the spaces in the input are encoded in the output URL as %20.

Source

%dw 2.0
output application/json
var urlPath = "content folder"
import * from dw::core::URL
---
{ "encodedURL" : compose(["http://examplewebsite.com/", "/page.html"], ["$(urlPath)"]) }

Output

{ "encodedURL" : "http://examplewebsite.com/content%20folder/page.html" }

Simplified Syntax

You can also call this function using the simplified syntax, which uses backticks (`) to enclose the string that includes the variable to encode.

Example

This example shows how to use the simplified syntax to obtain the same result as in the previous example.

Source

%dw 2.0
output application/json
var urlPath = "content folder"
import * from dw::core::URL
---
{ "encodedURL" : compose `http://examplewebsite.com/$(urlPath)/page.html` }

Output

{ "encodedURL" : "http://examplewebsite.com/content%20folder/page.html" }