--- title: conversion functions menu: main: parent: functions --- These are a collection of functions that mostly help converting from one type to another - generally from a `string` to something else, and vice-versa. ## `conv.Bool` **Alias:** `bool` **Note:** See also [`conv.ToBool`](#convtobool) for a more flexible variant. Converts a true-ish string to a boolean. Can be used to simplify conditional statements based on environment variables or other text input. _Added in gomplate [v0.2.0](https://github.com/hairyhenderson/gomplate/releases/tag/v0.2.0)_ ### Usage ``` conv.Bool in ``` ``` in | conv.Bool ``` ### Arguments | name | description | |------|-------------| | `in` | _(required)_ the input string | ### Examples _`input.tmpl`:_ ``` {{if bool (getenv "FOO")}}foo{{else}}bar{{end}} ``` ```console $ gomplate < input.tmpl bar $ FOO=true gomplate < input.tmpl foo ``` ## `conv.Default` **Alias:** `default` Provides a default value given an empty input. Empty inputs are `0` for numeric types, `""` for strings, `false` for booleans, empty arrays/maps, and `nil`. Note that this will not provide a default for the case where the input is undefined (i.e. referencing things like `.foo` where there is no `foo` field of `.`), but [`coll.Has`](../coll/#collhas) can be used for that. _Added in gomplate [v2.5.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.5.0)_ ### Usage ``` conv.Default default in ``` ``` in | conv.Default default ``` ### Arguments | name | description | |------|-------------| | `default` | _(required)_ the default value | | `in` | _(required)_ the input | ### Examples ```console $ gomplate -i '{{ "" | default "foo" }} {{ "bar" | default "baz" }}' foo bar ``` ## `conv.Dict` _(deprecated)_ **Deprecation Notice:** Renamed to [`coll.Dict`](../coll/#colldict) **Alias:** `dict` Dict is a convenience function that creates a map with string keys. Provide arguments as key/value pairs. If an odd number of arguments is provided, the last is used as the key, and an empty string is set as the value. All keys are converted to strings. This function is equivalent to [Sprig's `dict`](http://masterminds.github.io/sprig/dicts.html#dict) function, as used in [Helm templates](https://helm.sh/docs/chart_template_guide/functions_and_pipelines/). For creating more complex maps, see [`data.JSON`](../data/#datajson) or [`data.YAML`](../data/#datayaml). For creating arrays, see [`coll.Slice`](../coll/#collslice-_deprecated_). _Added in gomplate [v3.0.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.0.0)_ ### Usage ``` conv.Dict in... ``` ### Arguments | name | description | |------|-------------| | `in...` | _(required)_ The key/value pairs | ### Examples ```console $ gomplate -i '{{ conv.Dict "name" "Frank" "age" 42 | data.ToYAML }}' age: 42 name: Frank $ gomplate -i '{{ dict 1 2 3 | toJSON }}' {"1":2,"3":""} ``` ```console $ cat <