Handlebar use cases
General usage
Like said, Handlebars can be used where ever Frends Element parameter input field or Expression as long as the type is Text, JSON, XML, or SQL.
For instance, we can assign a piece of string to a variable like in the following example. The value of variable foo would be "Today is Thursday." if the execution of this element would happen on Thursday according to the Frends Agent clock.
Another general example would be the Handlebar usage in a Frends Task as in the example below. Here we are giving the file path as an Environment Variable reference in the Handlebar.
Similarly, we can manipulate any sort of text data with Frends and add as many Handlebars to a text input as needed. Ultimately, the Handlebars can contain any variable references, operators, and expressions in C# as long as the resulting object can be called with .ToString method.
For a simple example, if #var.numberA is 5 and #var.numberB is 6, the text
The number of {{#var.numberA}} is larger than the number of {{#var.numberB}}: {{#var.numberA > #var.numberB}}
would result in
The number of 5 is larger than the number of 6: False
JSON and XML templates
One traditional Handlebar usage is forming JSON or XML structures by laying out the wanted schema and injecting the needed values by referencing to variables in the Process with the Handlebars.
If we would like to form the following JSON, we could use it as the template and with Handlebars map the needed variable values or even uppercase values if needed.
With the following Handlebar usage, we can reference the variable properties, create C# expressions and form the required JSON.
Similarly, we can use the same concept with XML. To get the wanted XML structure we just reference the same values in similar fashion.
HTML templates
HTML is widely used for example in emails that are being sent from Frends as part of exception handling or end-user notifications. We can form HTML in a similar way as we did with JSON or XML.
First, we should just lay out the HTML document and inject the variable references of C# expressions in Handlebars wherever the use case requires them.
We could use the following HTML in Send Email Frends Task's Message.
For instance, in Outlook that Message would look like this:
Forming URLs
When dealing with HTTP requests with Frends, the URLs are commonly configured with Handlebars especially when there are multiple parameters dynamically being set.
For instance, we could have a Subprocess which takes multiple parameters that are then passed to the HTTP request Task URL:
{{#env.baseUrl}}/api/v1/{{#trigger.data.objectType}}?limit={{#trigger.data.limit}}&locator={{#trigger.data.locator}}
The next article is Introduction to JSON Objects