blob: 2f1dbd67c8a8c58d36f0ef279255b19765c5d53a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
.TH SSG-TEMPLATES 5 "December 2025" "ssg" "File Formats"
.SH NAME
ssg-templates \- ssg template format
.SH DESCRIPTION
ssg templates use Go's
.B html/template
syntax. Each HTML file in the templates directory is processed and rendered
to the output directory with the same filename.
.SH DATA
Data from JSON files in the data directory is made available to templates.
Each file becomes a template variable named after the file (without the
.I .json
extension).
.PP
For example, if
.I data/projects.json
contains:
.PP
.RS
.nf
[
{"name": "foo", "url": "https://example.com/foo", "featured": true},
{"name": "bar", "url": "https://example.com/bar", "featured": false}
]
.fi
.RE
.PP
It can be accessed in templates as
.BR .projects :
.PP
.RS
.nf
{{range .projects}}
<li><a href="{{.url}}">{{.name}}</a></li>
{{end}}
.fi
.RE
.SH FUNCTIONS
.SS filter
The
.B filter
function returns items from an array where a field equals a value.
.PP
.RS
.nf
{{range filter .projects "featured" true}}
<li>{{.name}}</li>
{{end}}
.fi
.RE
.PP
This would output only "foo" since it has
.B featured
set to
.BR true .
.SH SYNTAX
Templates use Go's text/template syntax:
.TP
.B {{.field}}
Output a field value.
.TP
.B {{range .items}}...{{end}}
Iterate over a list.
.TP
.B {{if .condition}}...{{end}}
Conditional rendering.
.TP
.B {{with .object}}...{{end}}
Set dot to the object for the block.
.PP
See the Go
.B html/template
documentation for full syntax details.
.SH FILES
.TP
.I data/*.json
JSON data files. Each becomes a template variable.
.TP
.I templates/*.html
HTML templates to render.
.SH SEE ALSO
.BR ssg (1),
.BR ssg-build (1)
|