This Commented CUE demonstrates how to use the built-in function text/template.Execute with data-driven templates to generate text output, using Go’s template format.

file.cue
package example

import "text/template"

tasklist: template.Execute(message, data)
message: """
	Hello, {{ .name }}.
	
	Here are the tasks you still need to do:
	-- TODO --------------------------------
	{{ range $T := .incomplete -}}
	▢ {{ printf "%s [estimated effort: %v]" $T.name $T.effort }}
	{{ end }}
	You've already completed these tasks - well done!
	-- DONE -----------------------------------------
	{{ range $T := .complete -}}
	✅︎ {{ $T.name }}
	{{ end -}}
	"""
data: {
	name: "Alex"
	tasks: [{
		name:     "Write CUE how-to guide"
		effort:   1
		complete: true
	}, {
		name:     "Train for 10k race"
		effort:   4
		complete: false
	}, {
		name:     "Violin practise"
		effort:   3
		complete: false
	}, {
		name:     "Go shopping"
		effort:   3
		complete: true
	}, {
		name:     "Feed cat"
		effort:   1
		complete: false
	},
	]
	complete: [for t in tasks if t.complete {t}]
	incomplete: [for t in tasks if !t.complete {t}]
}
TERMINAL
$ cue export -e tasklist --out text
Hello, Alex.

Here are the tasks you still need to do:
-- TODO --------------------------------
▢ Train for 10k race [estimated effort: 4]
▢ Violin practise [estimated effort: 3]
▢ Feed cat [estimated effort: 1]

You've already completed these tasks - well done!
-- DONE -----------------------------------------
✅︎ Write CUE how-to guide
✅︎ Go shopping
  • Go’s documentation of the template format used by text/template.Execute
  • The text/template built-in package
  • The example on this page is adapted from the excellent Cuetorials' page on text/template