Headers and Footers
Template actions in Word headers and footers are applied automatically when you call Apply. They use the same values and template functions as the main document; no separate header or footer API is required.
Add an action to the header or footer text in Word, for example:
text
{{.CompanyName}} | {{.ReportDate}}Then pass the corresponding fields as usual:
go
templateValues := struct {
CompanyName string
ReportDate string
}{
CompanyName: "Northwind",
ReportDate: "2026-10-18",
}
if err := docxTemplate.Apply(templateValues); err != nil {
return err
}Standard Go template actions and built-in functions can also be used in header and footer text. For example, a conditional can omit a label when its value is empty:
text
{{if .Confidential}}CONFIDENTIAL{{end}}