templates

package
v0.4.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package templates provides plugins access to Go templates.

Configuration: |-----------------------------------|-----------------------| | Env | JSON | | ----------------------------------|-----------------------| | PF__TEMPLATES__ALWAYSPARSE | templates.alwaysparse | | PF__TEMPLATES__DIRS | templates.dirs | |-----------------------------------|-----------------------|

Index

Constants

View Source
const PluginName = "templates"

Constant name for identifying the templates plugin.

Variables

This section is empty.

Functions

This section is empty.

Types

type TemplateData

type TemplateData struct {
	// Data contains the user-provided data passed to Render.
	Data interface{}
	// Config contains all configuration values from prefab.Config.
	Config map[string]interface{}
}

TemplateData is the wrapper struct passed to all templates during rendering. Templates should access the original data via .Data and configuration via .Config.

type TemplatePlugin

type TemplatePlugin struct {
	// contains filtered or unexported fields
}

TemplatePlugin exposes utilities for reading and rendering go templates.

func Plugin

func Plugin() *TemplatePlugin

Plugin returns a new TemplatePlugin.

func (*TemplatePlugin) Init

From prefab.InitializablePlugin.

func (*TemplatePlugin) Load

func (p *TemplatePlugin) Load(dirs []string) error

Load templates (*.tmpl) contained within the provided directory and all sub-directories.

func (*TemplatePlugin) Name

func (p *TemplatePlugin) Name() string

From prefab.Plugin.

func (*TemplatePlugin) Render

func (p *TemplatePlugin) Render(ctx context.Context, name string, data interface{}) (string, error)

Render executes a template by name with the provided data.

The data parameter is wrapped in a TemplateData struct before being passed to the template. Within templates, access your data fields using .Data.FieldName, not .FieldName directly. The Config field provides access to all configuration values.

Example template usage:

Hello, {{.Data.Name}}!
App version: {{.Config.app.version}}

Jump to

Keyboard shortcuts

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