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 Template Basics

Go templates use double curly braces for template expressions:

Hello, {{.name}}!

Variables

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

// Simple variable
{{.appName}}
// With formatting
Application: {{.appName | upper}}

Conditionals

{{if .enableTests}}
test:
enabled: true
{{end}}
{{if eq .environment "production"}}
replicas: 3
{{else}}
replicas: 1
{{end}}

Loops

{{range .services}}
- name: {{.name}}
port: {{.port}}
{{end}}

Pipelines

Chain functions using the pipe operator:

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

Sprig Functions

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

String Functions

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"}}

List Functions

// First item
{{first .items}}
// Last item
{{last .items}}
// Join with separator
{{.tags | join ", "}}

Date Functions

// Current date
{{now | date "2006-01-02"}}
// Format timestamp
{{.createdAt | date "Jan 2, 2006"}}

Encoding Functions

// Base64 encode
{{.secret | b64enc}}
// JSON encode
{{.config | toJson}}
// YAML encode
{{.config | toYaml}}

File and Folder Names

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

Jinja2-like Engine

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 %}!")
}

Whitespace Control

Control whitespace around template tags:

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

Learning Resources