Skip to content

Instantly share code, notes, and snippets.

@mostlylikeable
Created March 24, 2021 05:38
Show Gist options
  • Save mostlylikeable/137d9f1be39e1967a8397bc27caa512f to your computer and use it in GitHub Desktop.
Save mostlylikeable/137d9f1be39e1967a8397bc27caa512f to your computer and use it in GitHub Desktop.
Go Template Randomness
// Comment
`{{/* TODO: add more useful things */}}`
// Ternary var def with or
// $somevar := (.x ? .x : "")
`{{ $somevar := or .x "" }}`
// Ternary var def with and
// $somevar := (.x ? "" : .x)
`{{ $somevar := and .x "" }}`
// Chaining to concat str
// $somevar := (.x ? "has_" + .x : ""
`{{ $somevar := print (and .x "has_") (or .x "") }}`
// Access var from parent scope
`{{ $.x }}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment