Skip to content

Commit

Permalink
Add a custom delimited Go template to Zarf templating
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 committed Nov 13, 2023
1 parent 6c0e358 commit 5e4c26e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/pkg/utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"path/filepath"
"regexp"
"strings"
"text/template"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/message"
Expand Down Expand Up @@ -202,7 +203,24 @@ func ReplaceTextTemplate(path string, mappings map[string]*TextTemplate, depreca

textFile.Close()

return os.WriteFile(path, []byte(text), 0600)
zarfTemplate, err := template.New("").Delims("###{{", "}}###").Parse(text)
if err != nil {
return err
}

file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}

err = zarfTemplate.Execute(file, nil)
if err != nil {
return err
}

file.Close()

return nil

}

Expand Down

0 comments on commit 5e4c26e

Please sign in to comment.