with: Change evaluation context of the template part.
Subexpressions: Delimited by parentheses, invoke multiple helpers within a single mustache, and pass in the results of inner helper invocations as arguments to outer helpers.
$ curl --verbose http://localhost:8080/transformer-parameter-multiple/?id=2* Trying 127.0.0.1:8080...* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /transformer-parameter-multiple/?id=2 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse< HTTP/1.1 200 OK< Content-Type: application/json< Matched-Stub-Id: 407d8ac8-99c3-48be-9bc8-7989527977f5< Transfer-Encoding: chunked<{ "id": "2", "given": "given_2", "family": "family_2", "postcode": "BB2 2BB"}* Connection #0 to host localhost left intact
$ curl http://localhost:8080/helpers/string/ | json_pp{ "abbreviate" : "Truncate long sentence up...", "capitalize" : { "capitalize first letter of all words" : "ONLY First Letter Capitalized", "capitalize first letter of all words AND lower case other characters" : "Fully First Letter Capitalized" }, "capitalizeFirst" : "Only first character", "center" : { "center a string" : " centerAStringWithEmptySpaces ", "center string with padding" : "****centerAStringWithAsteriskPadding****" }, "cut" : { "remove number 7 from a string" : "string with number s", "remove spaces from a string" : "stringwithspaces" }, "dateFormat" : { "display current date and time in custom format" : "2023-12-05 01:09:13", "display current date in full format" : "Tuesday, 5 December 2023", "display current date in medium format" : "5 Dec 2023", "display current date in short format" : "05/12/2023", "parse timestamp from value in specific format, and display in full format" : "Monday, 21 June 2021" }, "defaultIfEmpty" : { "set NOTHING as value provided value is empty " : "NOTHING", "set empty string if value provided is empty" : "" }, "join" : { "join a list of items with custom joiner (last item in list is considered the joiner)" : "a-b-c", "join a list of items with custom joiner and prefix" : "[a-b", "join a list of items with custom joiner and suffix" : "a-b]", "join a list of items with custom joiner, prefix and suffix" : "[a-b]" }, "ljust" : { "left align a given string in a 30 width space" : "left aligned ", "left align a given string in a 30 width space with padding" : "left aligned******************" }, "lower" : "change value to lower case", "now" : { "display current date time" : "2023-12-05T01:09:13Z", "display current date time in custom format" : "2023-12-05 01:09:13.000067" }, "numberFormat" : { "format number in currency format" : "£30.00", "format number in currency format with locale" : "30,00 ¤", "format number in custom decimal format" : "3,000,000.000", "format number in integer format" : "30", "format number in percent format" : "3,000%", "format number with defined maximum integer and fraction digits" : "42.373", "format number with defined minimum integer and fraction digits" : "00.370" }, "replace" : "Replaces placeholder with provided replacement", "rjust" : { "right align a given string in a 30 width space" : " right aligned", "right align a given string in a 30 width space with padding" : "*****************right aligned" }, "slugify" : "creates-a-slug-useful-for-blog-post-urls", "stringFormat" : { "boolean" : "isSet: true isNotSet: false", "string" : "applies string formatting capabilities. All Java formatting options supported." }, "stripTags" : "Removes all (X)HTML tags", "substring" : { "substring from 3rd (exclusive) to 7th character" : "3456", "substring from 5th character (exclusive)" : "56789" }, "upper" : "CHANGE VALUE TO UPPER CASE", "yesno" : { "set true/false/null to ndio/hapana/labda (Swahili)" : "ndio | hapana | labda", "set true/false/null to sí/no/quizás (Spanish)" : "sí | no | quizás", "set true/false/null to yes/no/maybe" : "yes | no | maybe" }}
Conditional helpers
eq:
{{#assign 'id'}}{{request.query.id}}{{/assign}}{{#eq id '18'}}id is 18{{else}}id is not 18{{/eq}}
{{#eq id '18'}}id is 18{{else eq id '19'}}id is 19{{else}}id is not 18 or 19{{/eq}}
{{eq id '18'}}
{{eq id '18' yes='id is 18' no='id is not 18'}}
or:
{{#assign 'id'}}{{request.query.id}}{{/assign}}{{#or (eq id '18') (eq id '19')}}id is 18 or 19{{else}}id is not 18 or 19{{/or}}
{{or (eq id '18') (eq id '19') yes='id is 18 or 19' no='id is not 18 or 19'}}
$ curl http://localhost:8080/helpers/conditional/eq/?id=18 | python3 -m json.tool{ "eq with else": "id is 18", "eq with multiple else": "id is 18", "eq rendering 'true' or 'false'": "true", "eq rendering inlined values": "id is 18"}
$ curl http://localhost:8080/helpers/conditional/eq/?id=19 | python3 -m json.tool{ "eq with else": "id is not 18", "eq with multiple else": "id is 19", "eq rendering 'true' or 'false'": "false", "eq rendering inlined values": "id is not 18"}
$ curl http://localhost:8080/helpers/conditional/eq/?id=20 | python3 -m json.tool{ "eq with else": "id is not 18", "eq with multiple else": "id is not 18 or 19", "eq rendering 'true' or 'false'": "false", "eq rendering inlined values": "id is not 18"}
$ curl http://localhost:8080/helpers/conditional/or/?id=18 | python3 -m json.tool{ "or with else": "id is 18 or 19", "or rendering inlined values": "id is 18 or 19"}
$ curl http://localhost:8080/helpers/conditional/or/?id=19 | python3 -m json.tool{ "or with else": "id is 18 or 19", "or rendering inlined values": "id is 18 or 19"}
$ curl http://localhost:8080/helpers/conditional/or/?id=20 | python3 -m json.tool{ "or with else": "id is not 18 or 19", "or rendering inlined values": "id is not 18 or 19"}
Returns a boolean value indicating whether the string passed as the first parameter matches the regular expression passed in the second.
Note: Regular expressions with backslash+character (e.g., \w) does not seem to work.
l\\w+m and l\\\\w+m do not match lorem. (Double backslashes due to escaping in JSON.)
$ curl http://localhost:8080/helpers/matches/?string=lorem | python3 -m json.tool{ "string matches": "lor.+ matches lorem", "matches with if and else": "l[a-z]+m matches lorem"}
$ curl http://localhost:8080/helpers/matches/?string=l1rem | python3 -m json.tool{ "string matches": "", "matches with if and else": "l[a-z]+m does not match l1rem"}