gotemplate

command module
v3.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 24 Imported by: 0

README

gotemplate

Build Status Go Report Card Documentation

Description

Apply template over files ending with .template in the current directory. Every matching *.ext.template file will render a file named *.generated.ext. It is also possible to overwrite the original files.

Functions

Supports over a hundred functions:

  • Go template
  • Sprig
  • Advanced serialization and deserialization in JSON, YAML, XML and HCL
  • Looping and flow control functions of all kinds
  • Plus a whole bunch implemented in this repository
Syntax

Supports two distinct syntaxes (usable at the same time or individually)

Here are the statements to generate the following output:

Hello
World

Note: The - character trims whitespace. Otherwise, all lines are printed out as blank lines

Regular gotemplate
{{- $test := list "Hello" "World" }}
{{- range $word := $test }}
{{ $word }}
{{- end }}
Razor
@{test} := list("Hello", "World")
@-foreach($word := $test)
@{word}
@-end foreach
Using variables

Variables can be imported from various formats (YAML, JSON and HCL) and set as CLI arguments and then used in templates. Here's an example:

vars.json

{
  "my_var": "value"
}

Script:

gotemplate --var my_var2=value2 --import vars.json '{{ .my_var }} {{ .my_var2 }}'
  >>> value value2

More examples and statement in the documentation

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL