template

package
v0.65.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package template provides functions for applying go-templates within Zarf.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, s string, objs Objects) (string, error)

Apply takes a string, fills in the templates with the given Objects, and returns a new string.

func ApplyToFile

func ApplyToFile(ctx context.Context, src, dst string, objs Objects) error

ApplyToFile load a file path at src, fills in the templates with the given Objects, then writes the file to dst.

Types

type Objects

type Objects map[string]any

Objects provides a map of arbitrary data to be used in the template. By convention, top level keys are capitalized so users can see what fields are set by the system and which are set by user input. Example: Within a template, a user can access the Values from Object{ "Values": { "app": { "name": "foo" }}} With {{ .Values.app.name }} => "foo"

func NewObjects

func NewObjects(values value.Values) Objects

NewObjects instantiates an Objects map, which provides templating context. The "with" options below allow for additional template Objects to be included.

func (Objects) WithBuild

func (o Objects) WithBuild(build v1alpha1.ZarfBuildData) Objects

WithBuild takes the v1alpha1.ZarfBuildData section of a created package and makes it available in templating Objects.

func (Objects) WithConstants

func (o Objects) WithConstants(constants []v1alpha1.Constant) Objects

WithConstants Takes a slice of v1alpha1.Constants and unwraps it into the templating Objects map so constants can be accessed in templates by their key name.

func (Objects) WithMetadata

func (o Objects) WithMetadata(meta v1alpha1.ZarfMetadata) Objects

WithMetadata takes the v1alpha1.ZarfMetadata section of a created package and makes it available in templating Objects.

func (Objects) WithPackage

func (o Objects) WithPackage(pkg v1alpha1.ZarfPackage) Objects

WithPackage takes a v1alpha1.ZarfPackage and makes Metadata, Constants, and Build available on the Objects map.

func (Objects) WithValues

func (o Objects) WithValues(values value.Values) Objects

WithValues takes a value.Values and makes it available in templating Objects.

func (Objects) WithVariables

func (o Objects) WithVariables(vars variables.SetVariableMap) Objects

WithVariables takes a variables.SetVariableMap and unwraps it into the templating Objects map so variables can be accessed by their key name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL