Skip to content

Template Language

SKA uses the Go Template framework for templating your upstream blueprints. Additionally, it includes all Sprig functions for extended functionality.

Go templates use double curly braces for template expressions:

Hello, {{.name}}!

Access variables from your .ska-upstream.yaml inputs:

// Simple variable
{{.appName}}
// With formatting
Application: {{.appName | upper}}
{{if .enableTests}}
test:
enabled: true
{{end}}
{{if eq .environment "production"}}
replicas: 3
{{else}}
replicas: 1
{{end}}
{{range .services}}
- name: {{.name}}
port: {{.port}}
{{end}}

Chain functions using the pipe operator:

{{.appName | lower | replace " " "-"}}

SKA includes 100+ functions from the Sprig library. Here are the most useful ones:

FunctionDescriptionExample
upperUppercase{{.name | upper}}MYAPP
lowerLowercase{{.name | lower}}myapp
titleTitle case{{.name | title}}Myapp
replaceReplace string{{.name | replace "-" "_"}}
trimTrim whitespace{{.name | trim}}
quoteAdd quotes{{.name | quote}}"myapp"
defaultDefault value{{.port | default "8080"}}
// First item
{{first .items}}
// Last item
{{last .items}}
// Join with separator
{{.tags | join ", "}}
// Current date
{{now | date "2006-01-02"}}
// Format timestamp
{{.createdAt | date "Jan 2, 2006"}}
// Base64 encode
{{.secret | b64enc}}
// JSON encode
{{.config | toJson}}
// YAML encode
{{.config | toYaml}}

Template syntax works in file and folder names too:

src/
├── {{.appName}}/
│ ├── {{.appName}}_test.go
│ └── main.go

With appName: "myservice", this becomes:

src/
├── myservice/
│ ├── myservice_test.go
│ └── main.go

For templates that heavily use Go code (where {{ conflicts), SKA offers a Jinja2-like engine:

Terminal window
ska create --blueprint ./my-template --output ./project --engine jinja

This uses {% and %} delimiters instead:

func main() {
fmt.Println("Hello, {% .appName %}!")
}

Control whitespace around template tags:

// Trim leading whitespace
{{- .appName}}
// Trim trailing whitespace
{{.appName -}}
// Trim both
{{- .appName -}}