ns: conv title: conversion functions preamble: | 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. funcs: - name: conv.Bool alias: bool released: v0.2.0 description: | **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. pipeline: true arguments: - name: in required: true description: the input string rawExamples: - | _`input.tmpl`:_ ``` {{if bool (getenv "FOO")}}foo{{else}}bar{{end}} ``` ```console $ gomplate < input.tmpl bar $ FOO=true gomplate < input.tmpl foo ``` - name: conv.Default alias: default released: v2.5.0 description: | 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. pipeline: true arguments: - name: default required: true description: the default value - name: in required: true description: the input examples: - | $ gomplate -i '{{ "" | default "foo" }} {{ "bar" | default "baz" }}' foo bar - name: conv.Dict deprecated: Renamed to [`coll.Dict`](../coll/#colldict) alias: dict released: v3.0.0 description: | 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_). arguments: - name: in... required: true description: The key/value pairs examples: - | $ gomplate -i '{{ conv.Dict "name" "Frank" "age" 42 | data.ToYAML }}' age: 42 name: Frank $ gomplate -i '{{ dict 1 2 3 | toJSON }}' {"1":2,"3":""} - | $ cat <