diff --git a/docs/usage/templates.md b/docs/usage/templates.md index 73f333da8caf1d41b43780f841aa899aa40de93a..e4625c55044e614f1c2c0037d150d098e9536a30 100644 --- a/docs/usage/templates.md +++ b/docs/usage/templates.md @@ -37,6 +37,27 @@ If you want to print pretty JSON with Handlebars you can use the built-in functi In the example above `myvar` is a variable/field, that contains valid JSON. +### encodeURIComponent + +If you want to convert a string to a valid URI, use the built-in function `encodeURIComponent` like this: + +`{{{encodeURIComponent baseDir}}}` + +In the example above `baseDir` is the string you want to transform into a valid URI. + +Read the [MDN Web Docs, encodeURIComponent()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) to learn more. + +### replace + +The `replace` helper replaces _all_ found strings with the replacement string. +If you want to replace some characters in a string, use the built-in function `replace` like this: + +`{{{replace 'github.com', 'ghc', depName}}}` + +In the example above all matches of `github.com` will be replaced by `ghc` in `depName`. + +Read the [MDN Web Docs, String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) to learn more. + ### containsString Returns `true` if a given string is a substring.