Counts the length of a given string for use in other functions.
This example counts the length of the state field. If the length is exactly two characters, integrator.io capitalizes the output. If the length is not exactly two characters, the output is "Bad state value".
|
Template |
{{#compare state.length "===" 2}}{{uppercase state}}{{else}}Bad state value{{/compare}} |
|---|---|
|
Context |
{
"state": "ill"
}
{
"state": "il"
} |
|
Output |
Bad state value IL |
This example uses length with the compare handlebar to verify a phone number field has exactly 10 digits. If not, the output is ten zeros (0000000000).
|
Template |
{{#compare phone.length "===" 10}}{{phone}}{{else}}0000000000{{/compare}} |
|---|---|
|
Context |
{
"phone": "123456789"
} |
|
Output |
0000000000 |