From 0facdbf7de873449d3c6d17ea27187aa2d28e674 Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Wed, 9 Mar 2016 14:40:00 -0600 Subject: [PATCH] tpl: Add default function --- content/templates/functions.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/content/templates/functions.md b/content/templates/functions.md index e36e814d3..bbc81227f 100644 --- a/content/templates/functions.md +++ b/content/templates/functions.md @@ -28,6 +28,17 @@ and other basic tools; these are listed in the ## General +### default +Checks whether a given value is set and returns a default value if it is not. +"Set" in this context means true for booleans; non-zero for numeric types; +non-zero length for strings, arrays, slices, and maps; any struct value; or +non-nil for any other types. + +e.g. + + {{ .Params.font | default "Roboto" }} → default is "Roboto" + {{ default "Roboto" .Params.font }} → default is "Roboto" + ### delimit Loops through any array, slice or map and returns a string of all the values separated by the delimiter. There is an optional third parameter that lets you choose a different delimiter to go between the last two values. Maps will be sorted by the keys, and only a slice of the values will be returned, keeping a consistent output order.